包含 加载界面 游戏开始界面 游戏界面 和 得分界面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();