const {ccclass, property} = cc._decorator;
@ccclass
export default class Helloworld extends cc.Component {
@property(cc.Label)
label: cc.Label = null;
@property
text: string = 'hello';
async start () {
// init logic
this.label.string = this.text;
this.label.string = await this.testAsync();
}
async testAsync() : Promise<string> {
return new Promise<string>((resolve, reject)=>{
setTimeout(() => {
resolve("liang miao yi hou ");
}, 2000);
});
}
}
本文介绍了一种在游戏开发中利用异步函数进行UI更新的方法。通过定义装饰器和使用Promise,可以在不影响主线程的情况下实现平滑的UI更新效果。具体实现包括了如何设置组件属性并异步获取数据。
905

被折叠的 条评论
为什么被折叠?



