Created
September 10, 2021 13:45
Laya 1.x screen size fix
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
window.getAdapterInfo = function (config) { | |
let scaleX = 1; | |
let scaleY = 1; | |
let vw = window.innerWidth; | |
let vh = window.innerHeight; | |
let w = config.width; | |
let h = config.height; | |
config.scaleMode = config.scaleMode.toLowerCase(); | |
switch (config.scaleMode) { | |
case "exactfit": | |
scaleX = vw / w; | |
scaleY = vh / h; | |
break; | |
case "fixedwidth": | |
scaleX = scaleY = vw / w; | |
break; | |
} | |
return { | |
scaleX: scaleX, | |
scaleY: scaleY, | |
w: w, | |
h: h, | |
vw: vw, | |
vh: vh, | |
rw: w * scaleX, | |
rh: h * scaleY | |
}; | |
}; | |
Laya.init(600, 400, WebGL);// Replace 600 and 400 with your game's width and height. | |
Laya.stage.scaleMode = "exactfit";// exactfit is used as an example only. Replace it with the actual value in your game. | |
// Screen adaptation starts. | |
if(typeof getAdapterInfo !== "undefined"){ | |
var stage = Laya.stage; | |
var info = getAdapterInfo({width:600, height:400, scaleMode:"exactfit"});// Replace 600 and 400 with your game's width and height. | |
stage.designWidth = info.w; | |
stage.designHeight = info.h; | |
stage.width = info.rw; | |
stage.height = info.rh; | |
stage.scale(info.scaleX, info.scaleY); | |
} | |
// Screen adaptation ends. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment