问题解决了, 先翻转网页 - 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;
}
}
}