Reputation: 1346
My function to toggle fullscreen:
public void toggleFullScreen() {
if(!Gdx.graphics.isFullscreen())
Gdx.graphics.setFullscreenMode(Gdx.graphics.getDisplayMode());
else
Gdx.graphics.setWindowedMode(App.WIDTH, App.HEIGHT);
}
Works on desktop but not on mobile, why?
Upvotes: 0
Views: 389
Reputation: 1791
Does not work because the functionality is not supported by libgdx' HTML backend. Could be changed, you should open an issue or PR.
EDIT: After checking the backend source code, I must change my statement on SO. The code is in the backend since 2015 and is working for me on all systems except iOS.
Upvotes: 2
Reputation: 1346
I ended up calling a JavaScript function from LibGDX with JsInterop.
JavaScript
function toggleFullscreen() {
var canvas = document.getElementsByTagName("canvas")[0];
canvas.requestFullscreen();
}
Java
@JsMethod(namespace = GLOBAL)
public static native void toggleFullscreen();
Does not work with iOS though as Safari does not support Fullscreen API. I will just set Canvas width and height to Viewport width and height for iOS.
Upvotes: 1