Egret分步加载资源改写loading界面

 

第一步: (在配置文件default.res.json中)先确定好分步加载资源的资源列表,将loading界面所需要的资源区分出来.

第二步:(在脚本入口文件Main.ts中)修改资源加载顺序以使用loading界面所需的资源!

private async loadResource() {
    try {
        await RES.loadConfig("resource/default.res.json", "resource/");
        await RES.loadGroup("start");  /*加载start组的资源*/
        const loadingView = new LoadingUI();
        this.stage.addChild(loadingView);
        await RES.loadGroup('preload', 0, loadingView)
        this.stage.removeChild(loadingView);
    }
    catch (e) {
        console.error(e);
    }
}

第三步:(同第三步文件)绘制界面,使用加载好的资源,并获取stage属性调整资源

//例如:
private createView() {
    this.width = this.stage.stageWidth;
    this.height = this.stage.stageHeight;
    // 加载背景图
    let bg: egret.Bitmap = new egret.Bitmap(RES.getRes('UI_jiazai_Img_ditu_jpg'));
    bg.width = this.width;
    bg.height = this.height;
    this.addChild(bg);
}

 

posted @ 2020-03-19 09:54  前端法师  阅读(509)  评论(0)    收藏  举报