class Director {
public static instance:Director = null;
private stackLayer = [];
private gameLayer:Main = null;
public static getInstance() {
if (Director.instance == null) {
Director.instance = new Director();
}
return Director.instance;
}
public initWithMain(m:Main) {
if (this.gameLayer == null) {
this.gameLayer = m;
}
}
// ========================================================
//替换场景
public repleaceScene(layer:egret.DisplayObject) {
if (this.gameLayer != null && layer != null) {
this.gameLayer.removeChildren();
this.gameLayer.addChild(layer);
}
}
//添加场景
public pushScene(layer:egret.DisplayObject) {
if (this.gameLayer != null && layer != null) {
this.gameLayer.addChild(layer);
this.stackLayer.push(layer);
}
}
//移除场景
public popScene() {
if (this.gameLayer != null) {
var len = this.stackLayer.length;
if (len > 0) {
var layer = this.stackLayer[len - 1];
if (layer.parent == this.gameLayer) {
this.gameLayer.removeChild(layer)
Util.removeByElements(this.stackLayer, layer);
}
}
}
}
}
使用白鹭引擎对场景添加删除和替换的封装
最新推荐文章于 2020-04-16 00:22:56 发布