解决createjs适配手机横屏的问题

当用createjs做手机游戏开发,通常会遇到游戏横屏的问题,此时难以开发,下面通过一些代码去解决这一问题。

当开发时,可以通过谷歌浏览器打开手机横屏调试界面,进行页面的布局,并在布局前通过下面代码或得手机屏幕的宽高,然后进行适配:

1
2
3
4
5
6
7
8
9
10
//测试
// var gameScale = screenWidth/375;
// gameView.rotation = 90;
// gameView.x = screenWidth;
// gameView.y = 0;
// screenWidth = window.innerHeight;
// screenHeight = window.innerWidth;
//开发
screenWidth = window.innerWidth;
screenHeight = window.innerHeight;

当测试时,可以通过旋转屏幕的方式查看手机横屏后的效果:

1
2
3
4
5
6
7
8
9
10
//测试
var gameScale = screenWidth/375;
gameView.rotation = 90;
gameView.x = screenWidth;
gameView.y = 0;
screenWidth = window.innerHeight;
screenHeight = window.innerWidth;
//开发
//screenWidth = window.innerWidth;
//screenHeight = window.innerHeight;