Phaser3如何强制屏幕以横向模式打开

问题描述 投票:0回答:1

在Phaser3中,我想直接水平打开将在webview中运行的游戏。换句话说,我希望游戏能够水平打开,而无需用户转动手机。 下面的白色照片是游戏的垂直版本。 因此,当我垂直打开它时,游戏本身是横向的,但它不会以横向方式坐在屏幕上,它水平地站在屏幕顶部,因此不会转动游戏。 在此输入图片描述

这是我的游戏配置:

import Phaser, { Types } from "phaser";

const ratio = window.innerWidth < 600 ? 2 : 1;

const baseGameConfig: Types.Core.GameConfig = {
  type: Phaser.WEBGL,
  scale: {
    mode: Phaser.Scale.FIT,
    autoCenter: Phaser.Scale.CENTER_BOTH,
    width: window.innerWidth * ratio,
    height: window.innerHeight * ratio,
  },
  render: {
    antialias: true,
  },
};

export default baseGameConfig;


import { Types } from "phaser";

import baseGameConfig from "@games/config.base";

import Scenes from "./src/scenes";

export const DEFAULT_WIDTH: number = 1280;
export const DEFAULT_HEIGHT: number = 720;
export const MAX_WIDTH: number = 1920;
export const MAX_HEIGHT: number = 1080;
export let SCALE_MODE: "FIT" | "SMOOTH" = "SMOOTH";

const gameConfig: Types.Core.GameConfig = {
  ...baseGameConfig,
  title: "monkeygo",
  scene: Scenes.BootScene.scene,
  physics: {
    default: "arcade",
    arcade: {
      debug: process.env.NODE_ENV !== "production",
      gravity: {
        y: 800,
      },
      fps: 30,
      fixedStep: true,
      tileBias: 32,
    },
  },
  scale: {
    mode: Phaser.Scale.NONE,
    autoCenter: Phaser.Scale.CENTER_BOTH,
    width: DEFAULT_WIDTH,
    height: DEFAULT_HEIGHT,
  },
  input: {
    activePointers: 3,
  },
};

export default gameConfig;
javascript types responsive-design phaser-framework landscape
1个回答
0
投票

在创建函数中,您必须执行以下操作

if(this.scale.orientation.toString() == "landscape-primary"){
///your code here
}else{
//handle your portrait case
}

但是如果您使用旧版本的移相器,我认为这个解决方案可能有效

this.scale.forceLandscape = true;

© www.soinside.com 2019 - 2024. All rights reserved.