需求: 将egret项目内默认的loading页面效果修改为自定义的效果,加载资源完毕后直接进入项目首页
刚开始,写这个功能的时候,感觉又蒙又乱......
其实思路理清晰后,发现很容易.
需要修改的文件
- Main文件内部:
1)将默认加载的loading界面(LoadingUI界面) 修改为 自定义的loading界面(loadPage界面)
其实总共需要修改的代码只有三处:
// 加载进度界面
private loadingView: loadPage;
// 设置加载进度界面
wy.BaseViewManager.changeScene(loadPage);
this.loadingView = <loadPage>wy.BaseViewManager.nowScene;
- 写有自定义效果的loading页面内部:
1)将当前进度与总进度的逻辑写好
注意: 自定义loading界面的setProgress
函数(下方所示) 要与 Main 文件里面的this.loadingView.setProgress(event.itemsLoaded, event.itemsTotal);
对应
private line: egret.Shape;
private txt: egret.TextField;
private changeGraphics() {
this.car.x = this._distance;
this.line.graphics.beginFill(0x00ff00);
this.line.graphics.drawRoundRect(172, 641, this._linePrec, 8, 10, 10);
this.line.graphics.endFill();
this.txt.text = "" + this._prec + "%";
}
private _distance: number = 135;
private _linePrec: number = 0;
private _prec: number = 0;
public setProgress(cur, total): void { // 当前进度, 总进度
this._distance = cur / total * 350;
this._linePrec = cur / total * 280;
this._prec = Math.round(cur / total * 100);
if (cur / total == 1) {
wy.changeScene(scanPage, wy.PopType.ALPHAIN);
}
this.changeGraphics();
}