在 Phaser 中重置比例
Resetting scale in Phaser
我有一款用 Phaser 制作的游戏,我们正在尝试为其添加全屏功能。当我打电话给
this.game.scale.startFullScreen(false);
它保留了游戏的 maxHeight 和 maxWidth,因为它们是在预加载中设置的,所以它显示了一个以游戏为中心的黑色全屏,所以我为它创建了一个包装器,它可以工作,但当用户与 "Exit fullscreen button" 相反,点击逃逸。开始包装器将 maxWidth 和 maxHeight 设置为空,然后允许全屏显示,停止包装器将它们设置回默认值,当您按下 "exit fullscreen" 按钮时它工作正常,但是当我点击 escape它调用了我的函数,但没有重置屏幕,所以它退出浏览器全屏模式,但仍然比浏览器高 window.
这是我的完整代码:
var startFullscreen = function() {
// remove maxwith and maxheight
game.scale.maxWidth = null;
game.scale.maxHeight = null;
// set to fullscreen
game.scale.startFullScreen(false);
}
var stopFullscreen = function() {
// reset maxWidth and maxHeight
game.scale.maxWidth = 1000;
game.scale.maxHeight = 600;
// turn off fullscreen
if (game.scale.isFullScreen) { // if the user hit escape, fullscreen is already exited and we only need to reset the scale
game.scale.stopFullScreen();
} else {
// what goes here?
}
}
$(document).keyup(function (e) {
if (e.keyCode == 27) { // escape key maps to keycode `27`
stopFullscreen();
}
});
感谢任何帮助。提前致谢!
我将重置移动到全屏之后,这样当调用退出全屏时它们已经设置好了,所以它呈现正确,但我仍然愿意接受更好的解决方案。
var startFullscreen = function() {
// remove maxwith and maxheight
game.scale.maxWidth = null;
game.scale.maxHeight = null;
// set to fullscreen
game.scale.startFullScreen(false);
setTimeout(function () {
// resets height and width so the game will render correctly when fullscreen exits
game.scale.maxWidth = 1000;
game.scale.maxHeight = 600;
}, 500);
}
我有一款用 Phaser 制作的游戏,我们正在尝试为其添加全屏功能。当我打电话给
this.game.scale.startFullScreen(false);
它保留了游戏的 maxHeight 和 maxWidth,因为它们是在预加载中设置的,所以它显示了一个以游戏为中心的黑色全屏,所以我为它创建了一个包装器,它可以工作,但当用户与 "Exit fullscreen button" 相反,点击逃逸。开始包装器将 maxWidth 和 maxHeight 设置为空,然后允许全屏显示,停止包装器将它们设置回默认值,当您按下 "exit fullscreen" 按钮时它工作正常,但是当我点击 escape它调用了我的函数,但没有重置屏幕,所以它退出浏览器全屏模式,但仍然比浏览器高 window.
这是我的完整代码:
var startFullscreen = function() {
// remove maxwith and maxheight
game.scale.maxWidth = null;
game.scale.maxHeight = null;
// set to fullscreen
game.scale.startFullScreen(false);
}
var stopFullscreen = function() {
// reset maxWidth and maxHeight
game.scale.maxWidth = 1000;
game.scale.maxHeight = 600;
// turn off fullscreen
if (game.scale.isFullScreen) { // if the user hit escape, fullscreen is already exited and we only need to reset the scale
game.scale.stopFullScreen();
} else {
// what goes here?
}
}
$(document).keyup(function (e) {
if (e.keyCode == 27) { // escape key maps to keycode `27`
stopFullscreen();
}
});
感谢任何帮助。提前致谢!
我将重置移动到全屏之后,这样当调用退出全屏时它们已经设置好了,所以它呈现正确,但我仍然愿意接受更好的解决方案。
var startFullscreen = function() {
// remove maxwith and maxheight
game.scale.maxWidth = null;
game.scale.maxHeight = null;
// set to fullscreen
game.scale.startFullScreen(false);
setTimeout(function () {
// resets height and width so the game will render correctly when fullscreen exits
game.scale.maxWidth = 1000;
game.scale.maxHeight = 600;
}, 500);
}