【问题标题】:Disable auto-resizing in Phaser 2在 Phaser 2 中禁用自动调整大小
【发布时间】:2016-08-17 03:40:46
【问题描述】:

我正在使用 Phaser 2 创建一个响应式游戏。宽度固定为 360,高度计算为合适的比例。

var height = (360 * screen.height) / screen.width;
var game = new Phaser.Game(360, ratio, Phaser.AUTO, "", {preload: preload, create: create, update: update});

在 create() 函数中,我将其大小调整为 100%,因此屏幕被填满:

function create () {
   document.querySelector("canvas").style.width = "100%";
   document.querySelector("canvas").style.height = "100%";
   // more stuff...
}

但是,如果我现在单击或执行任何操作,画布会重新调整为 360xheight。我怎样才能禁用它?

谢谢

【问题讨论】:

标签: javascript html canvas phaser-framework


【解决方案1】:

Phaser 实际上能够将游戏/画布缩放到内置窗口的宽度或高度。

尝试改用ScaleManager。在你的情况下可能是SHOW_ALL,它可以在你的引导状态下设置(意思是在你的代码的早期):

this.scale.scaleMode = Phaser.ScaleManager.SHOW_ALL;

您可以在 this tutorial on Statethe official example 中看到实践中的示例。

【讨论】:

  • 这个答案与 Phaser 2 相关并且它已经过时了。 Phaser.ScaleManager.SHOW_ALL 不存在。
  • 在 Phaser 3 发布之前提出并回答了这个问题。 :) 我会相应地编辑问题标题。
猜你喜欢
  • 2011-10-27
  • 1970-01-01
  • 2015-07-27
  • 1970-01-01
  • 1970-01-01
  • 2012-03-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多