From bde3872f6806865151abc7825d76f897afd0300a Mon Sep 17 00:00:00 2001 From: jerrywwl Date: Wed, 3 Apr 2019 15:56:07 +0800 Subject: [PATCH] using landscape layout to device initialization --- cocos/core/game.js | 16 ++++++++++++++-- cocos/core/platform/CCView.js | 7 +++++-- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/cocos/core/game.js b/cocos/core/game.js index 2bd1047acf..d72ff2b477 100644 --- a/cocos/core/game.js +++ b/cocos/core/game.js @@ -699,8 +699,20 @@ class Game extends EventTarget { this._gfxDevice = new cc.WebGLGFXDevice(); } - const nativeWidth = Math.floor(screen.width * window.devicePixelRatio); - const nativeHeight = Math.floor(screen.height * window.devicePixelRatio); + cc.view.setOrientation(cc.macro.ORIENTATION_LANDSCAPE); + cc.view._initFrameSize(); + let nativeWidth = Math.floor(screen.width * window.devicePixelRatio); + let nativeHeight = Math.floor(screen.height * window.devicePixelRatio); + + if (nativeHeight > nativeWidth) { + let temp = localCanvas.width; + localCanvas.width = localCanvas.height; + localCanvas.height = temp; + + temp = nativeWidth; + nativeWidth = nativeHeight; + nativeHeight = temp; + } this._gfxDevice.initialize({ canvasElm: localCanvas, diff --git a/cocos/core/platform/CCView.js b/cocos/core/platform/CCView.js index 2a5bb09a63..8dae5800d6 100644 --- a/cocos/core/platform/CCView.js +++ b/cocos/core/platform/CCView.js @@ -1097,12 +1097,15 @@ class ContainerStrategy { locContainer.style.height = locCanvas.style.height = h + 'px'; } // Setup pixel ratio for retina display + /* var devicePixelRatio = view._devicePixelRatio = 1; if (view.isRetinaEnabled()) devicePixelRatio = view._devicePixelRatio = Math.min(2, window.devicePixelRatio || 1); + // Setup canvas - // locCanvas.width = w * devicePixelRatio; - // locCanvas.height = h * devicePixelRatio; + locCanvas.width = w * devicePixelRatio; + locCanvas.height = h * devicePixelRatio; + */ locCanvas.width = w; locCanvas.height = h;