gpt4 book ai didi

phaser-framework - 如何使用 Phaser 3 使 Canvas 响应?

转载 作者:行者123 更新时间:2023-12-04 10:14:12 25 4
gpt4 key购买 nike

以前我正在研究 Phaser 2,但现在我需要切换到 Phaser 3。

我试图让 Canvas 响应 ScaleManager但它不起作用。

我认为某些方法发生了变化,但我没有找到任何帮助来重新缩放舞台全屏。

var bSize = {
bWidth: window.innerWidth ||
root.clientWidth ||
body.clientWidth,
bHeight: window.innerHeight ||
root.clientHeight ||
body.clientHeight,
};

var game;

var canvas = document.getElementById("canvas");

function create() {

// Scaling options
game.scale.scaleMode = Phaser.ScaleManager.SHOW_ALL;

// Have the game centered horizontally
game.scale.pageAlignHorizontally = true;

// And vertically
game.scale.pageAlignVertically = true;

// Screen size will be set automatically
game.scale.setScreenSize(true);
}

window.onload = function() {

// Create game canvas and run some blocks
game = new Phaser.Game(
bSize.bWidth, //is the width of your canvas i guess
bSize.bHeight, //is the height of your canvas i guess
Phaser.AUTO,
'frame', { create: create });

canvas.style.position = "fixed";
canvas.style.left = 0;
canvas.style.top = 0;
}

最佳答案

Since v3.16.0, use the Scale Manager .简而言之:

var config = {
type: Phaser.AUTO,
scale: {
mode: Phaser.Scale.FIT,
parent: 'phaser-example',
autoCenter: Phaser.Scale.CENTER_BOTH,
width: 800,
height: 600
},
//... other settings
scene: GameScene
};

var game = new Phaser.Game(config);

Here是完整的代码和 here是一些使用 Scale Manager 的有用示例.

关于phaser-framework - 如何使用 Phaser 3 使 Canvas 响应?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51518818/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com