管理器类
// 场景管理器
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);
}
}
}