资源管理方式:① 进入游戏时立即预加载,用于主界面UI等;
② 在打开某个窗口时才加载,用于弹窗,活动UI等;
③ 进入主界面后偷偷在后台加载,用于关UI卡等;
event.itemsLoaded 得到目前已经加载的文件数量
event.itemsTotal 要加载的总文件数量
方法一:
this.LoadingUI = new LoadingUI();
this.stage.addChild(this.LoadingUI);
RES.addEventListener(RES.ResourceEvent.GROUP_PROGRESS, this.onResourceProgress, this);
RES.loadGroup('preload');
// 资源加载进度
private onResourceProgress(event: RES.ResourceEvent){
this.LoadingUI.setProgress(event.itemsLoaded,event.itemsTotal);
}
// 加载类
class LoadingUI {
public setProgress(): void{
// ......
}
}
方法二:
try{
await RES.loadGroup("preload", 0, loadingView);
}catch(e){
console.error(e);
}
class LoadingUI extends egret.Sprite implements RES.PromiseTaskReporter {
public constructor() {
super();
this.addEventListener(egret.Event.ADDED_TO_STAGE,this.createView,this);
}
private async createView() {
// 创建UI
}
private onFrame() {
// 动画
}
public onProgress(current: number, total: number): void {
// 显示数字
}