Egret 场景管理器

管理器类

// 场景管理器
module game {
    export class sceneManager extends eui.Component {
        public rootLayer: eui.UILayer;//起始场景
        public currentScene: eui.Component;//需要显示的场景
        private pop_scene: eui.Component;//弹出场景层

        private static _manager: sceneManager;
        public static get Instance() {
            sceneManager._manager = sceneManager._manager ? sceneManager._manager : new sceneManager();
            return sceneManager._manager;
        }

        public constructor() {
            super();
        }
        //切换场景
        public changeScene(s: eui.Component ) {
            if (this.currentScene) {
                this.rootLayer.removeChild(this.currentScene);
                this.currentScene = null;
            }
            this.rootLayer.addChild(s);
            this.currentScene = s;
        }
        //弹出场景层
        public pushScene(s: eui.Component) {
            this.popScene();
            if (!this.pop_scene) {
                this.rootLayer.addChild(s);
                this.pop_scene = s;
            }
        }
        //关闭场景层
        public popScene() {
            if (this.pop_scene) {
                this.rootLayer.removeChild(this.pop_scene);
                this.pop_scene = null;
            }
        }
    }
}

调用方法

module game {
	export class gameLogin extends eui.Component implements eui.UIComponent{
		public playBtn : eui.Button;
		public constructor() {
			super();
		}
		protected partAdded(partName:string,instance:any):void
		{
			super.partAdded(partName,instance);
		}
		protected childrenCreated():void
		{
			super.childrenCreated();
			this.playBtn.addEventListener(egret.TouchEvent.TOUCH_TAP,this.btnClick,this);
		}
		private btnClick():void{
			let mainScene = new game.mainScene(); 
			game.sceneManager.Instance.changeScene(mainScene);
		}
	}
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值