包含 加載界面 遊戲開始界面 遊戲界面 和 得分界面this
// 程序入口 class GameMain{ private loading:Loading; //讀條界面 private entry:Entry; //遊戲入口 private game:Game; //遊戲界面 private score:Score; //得分界面 constructor() { //初始化引擎 Laya.init(GlobalConfig.STAGE_WIDTH,GlobalConfig.STAGE_HEIGHT,Laya.WebGL); Laya.stage.screenMode = Laya.Stage.SCREEN_HORIZONTAL; //進入加載資源頁面 this.loading = new Loading(); Laya.stage.addChild(this.loading); //開始加載資源 Laya.loader.load("res/atlas/home.atlas",Laya.Handler.create(this,this.onResourceLoadingComplete),Laya.Handler.create(this,this.onProgress),Laya.Loader.ATLAS); } //進度變化 private onProgress(loadNum:number):void { this.loading.setText("資源加載中,當前進度:"+parseInt(loadNum*100+"")+"%"); } //加載完成 private onResourceLoadingComplete():void{ Laya.stage.removeChild(this.loading); this.GameInit(); } //遊戲入口UI初始化 private GameInit():void{ this.entry = new Entry(); Laya.stage.addChild(this.entry); this.entry.size(GlobalConfig.STAGE_WIDTH,GlobalConfig.STAGE_HEIGHT); this.entry.on(Laya.Event.CLICK,this,this.onStartGame); } //進入遊戲界面 private onStartGame():void{ Laya.stage.removeChild(this.entry); this.game = new Game(); Laya.stage.addChild(this.game); this.game.on(GameEvents.GAME_OVER_EVENT,this,this.onGameOver); } //遊戲從新開始 private onReset():void{ Laya.stage.removeChild(this.score); this.GameInit(); } //遊戲結束自定義事件 private onGameOver():void{ Laya.stage.removeChild(this.game); this.score = new Score(); Laya.stage.addChild(this.score); this.score.size(GlobalConfig.STAGE_WIDTH,GlobalConfig.STAGE_HEIGHT); this.score.on(Laya.Event.CLICK,this,this.onReset); } } new GameMain();