Skip to content

Instantly share code, notes, and snippets.

@riskers
Last active June 8, 2016 02:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save riskers/fdde38b89535a16fcae7197cafc3435f to your computer and use it in GitHub Desktop.
Save riskers/fdde38b89535a16fcae7197cafc3435f to your computer and use it in GitHub Desktop.
egret init include loading view
class LoadingUI extends egret.Sprite {
public constructor(stageWidth,stageHeight) {
super();
this.createView(stageWidth,stageHeight);
}
private textField: egret.TextField;
private bg: egret.Shape;
private progress = new egret.Shape;
private maskBar;
private createView(stageWidth,stageHeight): void {
this.bg = new egret.Shape;
this.bg.graphics.beginFill(0x434b42);
this.bg.graphics.drawRect(0,0,stageWidth,stageHeight);
this.bg.graphics.endFill();
this.addChild(this.bg);
this.textField = new egret.TextField();
this.addChild(this.textField);
this.textField.width = 480;
this.textField.height = 100;
this.textField.anchorOffsetX = this.textField.width / 2;
this.textField.anchorOffsetY = this.textField.height / 2;
this.textField.x = stageWidth / 2;
this.textField.y = stageHeight / 2;
this.textField.textColor = 0xfffa5c;
this.textField.textAlign = "center";
this.progress.width = 300;
this.progress.height = 20;
this.progress.visible = false;
this.progress.anchorOffsetX = this.progress.width / 2;
this.progress.x = stageWidth / 2;
this.progress.y = stageHeight / 2 - 80;
this.progress.graphics.beginFill(0x53a98f);
this.progress.graphics.drawRect(0,0,300,10);
this.progress.graphics.endFill();
this.addChild(this.progress);
}
public setProgress(current,total): void {
this.progress.visible = true;
var par = Math.floor(current / total * 100)
this.maskBar = new egret.Rectangle(0,0,par * 3,10)
this.progress.mask = this.maskBar;
this.textField.text = par + '%';
}
}
class Main extends egret.DisplayObjectContainer {
private loadingView: LoadingUI;
static stageWidth: number;
static stageHeight: number;
public constructor() {
super();
this.addEventListener(egret.Event.ADDED_TO_STAGE,this.onStage,this);
}
private onStage(){
Main.stageWidth = this.stage.stageWidth;
Main.stageHeight = this.stage.stageHeight;
RES.addEventListener(RES.ResourceEvent.CONFIG_COMPLETE,this.configcom,this);
RES.loadConfig("resource/default.res.json","resource/");
}
private configcom(){
RES.removeEventListener(RES.ResourceEvent.CONFIG_COMPLETE,this.configcom,this);
RES.addEventListener(RES.ResourceEvent.GROUP_PROGRESS,this.onResourceProgress,this);
RES.addEventListener(RES.ResourceEvent.GROUP_COMPLETE,this.onResourceLoadCom,this);
this.loadingView = new LoadingUI(this.stage.stageWidth,this.stage.stageHeight);
this.stage.addChild(this.loadingView);
RES.loadGroup('preload');
}
private onResourceProgress(e) {
this.loadingView.setProgress(e.itemsLoaded,e.itemsTotal);
}
private onResourceLoadCom(){
this.loadingView.visible = false;
RES.removeEventListener(RES.ResourceEvent.GROUP_PROGRESS,this.onResourceProgress,this);
RES.removeEventListener(RES.ResourceEvent.GROUP_COMPLETE,this.onResourceLoadCom,this);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment