Laya.stage.on(Laya.Event.RESIZE, this, this.OnresizeFn);
Laya.stage.alignH = "center";//"left";
Laya.stage.alignV = "middle";//"top";
Laya.stage.screenAdaptationEnabled=true;
oldWith: number = 0;
oldheight: number = 0;
HengPing(isFirst: boolean): void {
if (Laya.stage != null)
{
this.oldWith = Laya.Browser.clientWidth;
this.oldheight= Laya.Browser.clientHeight;
}
console.log("设置横屏" + isFirst);
if (isFirst)
Laya3D.init(1280, 720, true);
else
Laya.stage.width = 1280; Laya.stage.height = 720;
//Laya.stage.scaleMode = Laya.Stage.SCALE_FIXED_WIDTH;
Laya.stage.scaleMode = Laya.Stage.SCALE_SHOWALL;
}
ShuPing(isFirst: boolean): void {
if (Laya.stage != null)
{
this.oldWith = Laya.Browser.clientWidth;
this.oldheight= Laya.Browser.clientHeight;
}
console.log("设置竖屏" );
if (isFirst)
Laya3D.init(720, 1280, true);
else
Laya.stage.width = 720; Laya.stage.height = 1280;
Laya.stage.scaleMode = Laya.Stage.SCALE_SHOWALL;
}
firstInit: boolean = true;
OnresizeFn(): void {
// return;
console.log("isSizeChang" +this.isSizeChang());
//if (this.firstInit==true) return;
//if (this.oldWith == Laya.Browser.clientWidth) return;
if (this.isSizeChang()==false) return;
console.log("Onresize " );
this.ChangeSize();
}
isSizeChang():boolean
{
if(this.oldWith!= Laya.Browser.clientWidth) return true;
if(this.oldheight!= Laya.Browser.clientHeight) return true;
return false;
}
ChangeSize(): void {
if (Laya.Browser.clientWidth > Laya.Browser.clientHeight)
this.HengPing(false);
else
this.ShuPing(false);
}