Fullscreen Libgdx HTML5 not working on mobile

别来无恙 提交于 2019-12-11 17:24:58

问题


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?


回答1:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/55884972/fullscreen-libgdx-html5-not-working-on-mobile

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!