您的位置:首页 > 其它

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

2020-02-29 17:56 507 查看

程序入口存放每个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第二页。

转载于:https://www.cnblogs.com/Alisa-Davillver/p/6398422.html

  • 点赞
  • 收藏
  • 分享
  • 文章举报
anquanxie2713 发布了0 篇原创文章 · 获赞 0 · 访问量 614 私信 关注
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: