web 游戏 适配的问题

2.4.4版本, web 端, 设备:哈奇光屏

用uc浏览器打开我们的 web端游戏的时候。
我不确定当前是横屏还是竖屏, 这个在设备上应该是自动调控的。

网页打开后我打印 windows.orientation 参数 是 90 度 表示横屏。
可是 cc.view.getFrameSize() 720 1150
window.innerWidth,window.innerHeight 720 1150
都显示当前是竖屏 的宽高, 这是为什么呢。
然后游戏内容显示也是竖屏显示。
我的游戏设置了强制横屏, 显示的内容和手机锁定竖屏的时一样。 不想要这样的效果。

有什么办法能够让他根据 windows.orientation 参数 判断当前是横屏然后做横屏的显示呢

想知道cocos 是怎么判定 当前设备是横屏还是竖屏的

教你web端横屏改为逆时针旋转90度 有点类似这个问题,我可以翻转游戏 -270度,假装横屏, 但是要调整触碰点, 避免按钮点不到

问题解决了, 先翻转网页 - 90度, 这样我的游戏界面就是倒过来了, 然后调整一下输入坐标, 问题解决。。 教你web端横屏改为逆时针旋转90度 参考他的代码

自己写的代码如下
export function viewAdaptation (){

onRotateView()

cc.view.setResizeCallback(function(){

    onRotateView()

})

}

function onRotateView(){

let w = window.innerWidth

let h = window.innerHeight

if(h > w){  

    cc.game.container.style['-webkit-transform'] = 'rotate(-90deg)';

    cc.game.container.style.transform = 'rotate(-90deg)';

    setTimeout(function () {

        cc.game.container.style['margin'] = cc.view.getFrameSize().width + 'px 0px 0px';

    });

    cc.view.convertToLocationInView = function (tx, ty, relatedPos) {

        let result = cc.v2();

        let posLeft = relatedPos.adjustedLeft ? relatedPos.adjustedLeft : relatedPos.left;

        let posTop = relatedPos.adjustedTop ? relatedPos.adjustedTop : relatedPos.top;

        let x = this._devicePixelRatio * (tx - posLeft);

        let y = this._devicePixelRatio * (posTop + relatedPos.height - ty);

        if (this._isRotated) {

            result.x = y;

            result.y = cc.view.getViewportRect().height - x;

        }

        else {

            result.x = x;

            result.y = y;

        }

        return result;

    }

}else{

    cc.view.convertToLocationInView = function (tx, ty, relatedPos) {

        let result = cc.v2();

        let posLeft = relatedPos.adjustedLeft ? relatedPos.adjustedLeft : relatedPos.left;

        let posTop = relatedPos.adjustedTop ? relatedPos.adjustedTop : relatedPos.top;

        let x = this._devicePixelRatio * (tx - posLeft);

        let y = this._devicePixelRatio * (posTop + relatedPos.height - ty);

        if (this._isRotated) {

            result.x = cc.game.canvas.width - y;

            result.y = x;

        }

        else {

            result.x = x;

            result.y = y;

        }

        return result;

    }

}

}

2赞

该主题在最后一个回复创建后14天后自动关闭。不再允许新的回复。