egret H5游戏异步加载资源,优化游戏

1、将大的动画图片,需要异步加载的数据单独放在一个组中
例如:组名 gift

2、在调用动画前先加载资源。在渲染

 RES.loadGroup("downanim").then(() => {
            var data = RES.getRes("downAppAnim_json");
            var txtr = RES.getRes("downAppAnim_png");
            var mcFactory: egret.MovieClipDataFactory = new egret.MovieClipDataFactory(data, txtr);
            if (mcFactory) {
                var role: egret.MovieClip = new egret.MovieClip(mcFactory.generateMovieClipData("downAppAnim"));
                this.animGroup.addChild(role);
                role.gotoAndPlay("play", -1);
                role.width = 180;
                role.height = 180;
                role.addEventListener(egret.Event.COMPLETE, function (e: egret.Event): void {
                    egret.log("play over!")
                }, this);
                role.addEventListener(egret.Event.LOOP_COMPLETE, function (e: egret.Event): void {

                }, this);
                role.addEventListener(egret.MovieClipEvent.FRAME_LABEL, function (e: egret.MovieClipEvent): void {
                    egret.log("frameLabel:" + e.frameLabel);
                }, this);
            
            }

        }, () => { });

你可能感兴趣的:(H5,egret)