LayaBox的場景切換


class GamOver extends ui.GameOverUI{
    constructor(){
         super();
         this.restart_btn.on(Laya.Event.CLICK,this,this.restartGame);
    }
    
    //點擊重新開始按鈕觸發下面的事件
    public restartGame():void{
        this.removeSelf();              //移除游戲結束界面
        GameMain.GameView.removeSelf(); //移除游戲主體
        Laya.stage.addChild(GameMain.GameStart); //添加游戲開始界面
    }
    
    //添加分數或者排名到頁面上去
    public addScore(score:number):void{
        var textScore:Laya.Text = new Laya.Text();
        textScore.text = String(score);  //或者是 score.toString();  ts的強制類型轉換
        //textScore.x = 280;
        textScore.align = "center";
        textScore.width = 640;
        textScore.height = 800;
        textScore.valign = "middle";
        textScore.fontSize = 80;
        textScore.color = "red";
        Laya.stage.addChild(textScore);
    }
    
}

例如這里的例子,這里是在游戲結束的 時候點擊重新開始會執行restartGame()的方法,里面就用removeSelf()的方法來移除當前的類GamOver的UI類,就意味着游戲結束的界面被移除了,不再顯示了,然后再下面的Laya.stage.addChild()方法里面又添加了GameStart的UI對象,就顯示游戲開始的界面了,還可以通過下面的方法銷毀或者移除當前UI類,從而達到場景切換的功能(其實也是對節點的操作):


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM