From 449e52186316cb2bcea2da227dd30a937583b279 Mon Sep 17 00:00:00 2001 From: JianMiau Date: Sun, 2 Jan 2022 11:16:05 +0800 Subject: [PATCH] =?UTF-8?q?[mod]=20=E8=9E=A2=E5=B9=95=E6=97=8B=E8=BD=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- assets/Script/Manager.ts | 31 +++++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/assets/Script/Manager.ts b/assets/Script/Manager.ts index f7b28a1..56301e0 100644 --- a/assets/Script/Manager.ts +++ b/assets/Script/Manager.ts @@ -21,14 +21,29 @@ export default class Manager extends cc.Component { private _resize(): void { let Canvas: cc.Canvas = cc.Canvas.instance; - Canvas.designResolution = cc.size(Canvas.designResolution.height, Canvas.designResolution.width); - // let rect: DOMRect = cc.game.canvas.getBoundingClientRect(); - // /** 判断是否是横屏 */ - // let landscape: boolean = false; - // if (rect.width > rect.height) { - // landscape = true; - // } - // // 根据横竖屏调整节点的位置适配等 + let rect: DOMRect = cc.game.canvas.getBoundingClientRect(); + /** 判断是否是横屏 */ + let landscape: boolean = false; + if (rect.width > rect.height) { + landscape = true; + } + // 根据横竖屏调整节点的位置适配等 + let frameSize: cc.Size = cc.view.getFrameSize(); + if (landscape) { + // 横屏 + cc.view.setOrientation(cc.macro.ORIENTATION_LANDSCAPE); + if (frameSize.height > frameSize.width) { + cc.view.setFrameSize(frameSize.height, frameSize.width); + } + Canvas.designResolution = cc.size(1920, 1080); + } else { + // 竖屏 + cc.view.setOrientation(cc.macro.ORIENTATION_PORTRAIT); + if (frameSize.width > frameSize.height) { + cc.view.setFrameSize(frameSize.height, frameSize.width); + } + Canvas.designResolution = cc.size(1080, 1920); + } } //#endregion