[]横竖屏切换,此引擎渲染有BUG
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);
}
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);
}
没有找到相关结果
已邀请:
要回复问题请先登录
4 个回复
杰
赞同来自:
错误效果
HengPing()//横屏方法
ShuPing()//竖屏幕方法
ShuPing和HengPing 方法要执行1次,然后等个2秒执行1次,再等待2秒再执行一次就可以了。。。有时候要执行数十次才能显示预期效果
本人是4年前端,现在转H5开发
此问题从早上12点开始研究 ,现在已经是凌晨2:50
临时解决方法,意思是先执行一次横屏,3秒后再执行一次
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();
setTimeout(()=>{ this.ChangeSize();this.ChangeSize();},3000);
}
杰
赞同来自:
执行横屏适配代码结果是这样
layabox
赞同来自:
屏幕方向:自动横屏与自动竖屏的设置
https://ldc.layabox.com/doc/?nav=zh-ts-1-8-2
rabbit
赞同来自: