2020年5月22日
自定义loading
class LoadingUI extends egret.Sprite implements RES.PromiseTaskReporter {
publicconstructor() {
super();
this.addEventListener(egret.Event.ADDED_TO_STAGE, this.createView, this);
}
privateasynccreateView() {
letmy_bg: eui.Rect = neweui.Rect;
my_bg.fillColor = 0xffffff;
my_bg.width = this.stage.stageWidth;
my_bg.height = this.stage.stageHeight;
this.addChild(my_bg);
awaitthis.addDBArmature();
this.initLoading();
}
/**百分比位图 */
// private loadingContainer: egret.DisplayObjectContainer;
private text: egret.BitmapText;
publicbar_top: any = neweui.Image();
publicbar_move: any = neweui.Image();
publicbar_mask: any = neweui.Image();
publicbar_bot: any = neweui.Image();
publiclocal_x = 650;
publiclocal_y = 697;
privateinitLoading() {
this.text = newegret.BitmapText();
letfnt = RES.getRes(“black_fnt_fnt”); //加载字体位图
this.text.font = fnt;
this.text.text = “0%”;
this.text.textAlign = “center”;
// this.text.y = 33;
this.text.width = this.stage.stageWidth;
this.text.height = 30;
this.text.y = 850;
this.addChild(this.text);
}
publiconProgress(current: number, total: number): void {
this.text.text = Math.floor((current / total) * 100).toString() + “%”;
}
//动画
publicasync addDBArmature() {
awaitdbFactory.createArmature(“Loading”).then((armature) => {
this.addChild(armature.display);
armature.display.x = this.stage.stageWidth / 2;
armature.display.y = this.local_y – 120;
armature.play(“Loading001”, 0)
})
}
}