【发布时间】:2016-01-22 23:20:32
【问题描述】:
我有一个使用 Phaser 制作的游戏,我们正在尝试为其添加全屏功能。当我打电话时
this.game.scale.startFullScreen(false);
它保留了游戏的 maxHeight 和 maxWidth,因为它们是在预加载中设置的,所以它显示了一个以游戏为中心的黑色全屏,所以我为它创建了一个包装器,它可以工作,但当用户点击退出时不会而不是“退出全屏按钮”。 start wrapper 将 maxWidth 和 maxHeight 设置为 null,然后允许全屏显示, stop wrapper 将它们设置回默认值,当你按下“exit fullscreen”按钮时它工作正常,但是当我点击逃避它调用我的函数,但不重置屏幕,因此退出浏览器全屏模式,但仍高于浏览器窗口。
这是我的完整代码:
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();
}
});
感谢任何帮助。提前致谢!
【问题讨论】:
标签: javascript game-engine phaser-framework