[0]构造器中设置页面宽高后,在onopen该页面后失效


 constructor() {
        super();
        this.width = Laya.stage.width;
        this.height = Laya.stage.height;
        console.log(this.width,this.height,"-------------2")
    }
    private addEvent(){
        this.btn_close.on(Laya.Event.CLICK,this,this.closed);
    }

    private offEvent(){
        this.btn_close.off(Laya.Event.CLICK,this,this.closed);
    }

    onOpened(heroID: number) {
        console.log(this.width,this.height,"-------------2")
}
上面是代码,constructor()中的console打出来的是1559 720
onOpened中的console打出来的是1280 720
已邀请:

pikapikaqiu

赞同来自:

UI类在创建后会根据UI的设置数据去重新设置一遍。你在constructor里面的代码执行修改属性没用。放到onAwake()里面。

要回复问题请先

商务合作
商务合作