LayaBox在使用removeSelf()方法移除场景的时候应该注意什么

程序入口存放每个ui界面的对象(这里有三个)

// 程序入口
class GameMain{
    public static mainUI:MainUI;       //用于存放游戏主页ui的成员属性
    public static secondUI:SecondUI;   //保存第二页ui
    public static thirdUI:ThirdUI;     //保存第三页ui
    private group:Array<number> = [];    //用于存放选中box的引索
    private allData:Array<any>;   //用于存放股票数据的数组
    private btnState:boolean = true;           //全选和取消全选按钮的状态
    private dataSource: Array<any> = []; //存储list中的每个box

这里的三个UI成员属性都是public static属性的,方便全局调用

下面是第三页ui的操作

class ThirdUI extends ui.ThirdUI{
    constructor(){
        super();
        this.bingoAni.url = "../laya/assets/ui/output/bingo_ani.swf";
        this.bingoLogo.skin = "../laya/assets/ui/bingoLogo.png";
        this.return.skin = "../laya/assets/ui/return.png";
        this.return.on(Laya.Event.CLICK,this,this.onReturn);  //点击首页的我要申购按钮切换到求神的页面
    }

        //点击恭喜中签触发下面的事件
        private onReturn():void{
            //console.log("恭喜中签!!");
            this.removeSelf();      //移除当前(第三页)
            GameMain.mainUI.removeSelf();  //移除第一页
            GameMain.secondUI.y = -60;
            Laya.stage.addChild(GameMain.secondUI);
        }
}

这里是一个返回上一页的例子,注意如果要removeSelf()其他页面,显示其中一个页面的话,必须要移除彻底,即除开要显示的页面意外,其他所有的页面都要进行removeSelf()的操作,不能有漏,不然再addChild()回来的时候会报错。例如这里,我要显示第二页,那么我把第一和第三页都remov掉了,只addChild第二页。

posted @ 2017-02-14 17:01  CTO++  阅读(3653)  评论(1编辑  收藏  举报