在 Phaser 2 中禁用自动调整大小
Disable auto-resizing in Phaser 2
我正在使用 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...
}
但是,如果我现在单击或执行任何操作,canvas 会重新调整为 360x 高度。我怎样才能禁用它?
谢谢
Phaser 实际上能够将 game/canvas 缩放到 window 内置的宽度或高度。
请尝试使用 ScaleManager。在你的情况下可能 SHOW_ALL
,它可以在你的启动状态下设置(意味着在你的代码的早期):
this.scale.scaleMode = Phaser.ScaleManager.SHOW_ALL;
您可以在 this tutorial on State, and the official example.
中看到实践中的示例
我正在使用 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...
}
但是,如果我现在单击或执行任何操作,canvas 会重新调整为 360x 高度。我怎样才能禁用它?
谢谢
Phaser 实际上能够将 game/canvas 缩放到 window 内置的宽度或高度。
请尝试使用 ScaleManager。在你的情况下可能 SHOW_ALL
,它可以在你的启动状态下设置(意味着在你的代码的早期):
this.scale.scaleMode = Phaser.ScaleManager.SHOW_ALL;
您可以在 this tutorial on State, and the official example.
中看到实践中的示例