【问题标题】:Resetting scale in Phaser在 Phaser 中重置比例
【发布时间】: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


【解决方案1】:

我将重置移动到在我们进入全屏之后,这样在调用退出全屏时它们已经设置好了,所以它呈现正确,但我仍然愿意接受更好的解决方案。

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);
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2010-10-25
    • 2022-09-23
    • 1970-01-01
    • 2022-12-03
    • 1970-01-01
    • 1970-01-01
    • 2014-08-08
    • 1970-01-01
    相关资源
    最近更新 更多