4ian / GDevelop

🎮 Open-source, cross-platform 2D/3D/multiplayer game engine designed for everyone.
https://gdevelop.io
Other
9.01k stars 786 forks source link

gdjs.RuntimeGamePixiRenderer.prototype.isFullScreen does not detect users pressing escape #2162

Open jonasfj opened 3 years ago

jonasfj commented 3 years ago

gdjs.RuntimeGamePixiRenderer.prototype.isFullScreen does not detect that users press escape and leave fullscreen mode.

This is easy to see from source for RuntimeGamePixiRenderer.

To Reproduce

Classic application for this is a fullscreen button, which is only visible when not in fullscreen mode screenshot-button

Solution

Other details

jonasfj commented 3 years ago

For anyone looking to work around this issue the following code-snippet should do:

// This ensures that we restore state when user exits fullscreen using escape
if (!window._gdjsFullScreenPatch) {
    window._gdjsFullScreenPatch = true;
    const game = runtimeScene.getGame();
    document.addEventListener('fullscreenchange', () => {
        game.getRenderer().setFullScreen(document.fullscreenElement != null);
    });
    document.addEventListener('webkitfullscreenchange', () => {
        game.getRenderer().setFullScreen(document.fullscreenElement != null);
    });
    document.addEventListener('mozfullscreenchange', () => {
        game.getRenderer().setFullScreen(document.fullscreenElement != null);
    });
}

Running it once in the beginning of an initial scene should be sufficient.

(this is not something I would suggest as an official patch, just a quick hack to workaround the issue)