简体   繁体   中英

How to make a LibGDX application launch at the same resolution as the browser frame

So I am attempting to make my game to where when launched (from browser), will take up all of the screen in the browser. In my HTML launcher code I have to feed it a width and a height, so I have been trying to access the width and height of the browser frame to initialize the game. So far I haven't gotten anything to work. These are the attempts I made to access the width and height in order.

  1. Gdx.graphics.getWidth() and Gdx.graphics.getHeight()
  2. Gdx.app.getGraphics().getWidth() and Gdx.app.getGraphics().getHeight()
  3. this.getGraphics().getWidth() and this.getGraphics().getHeight()

All of these when used on this code: return new GwtApplicationConfiguration(int width, int height); display nothing. Only when I hard-code a value in does it show anything, and hard-coding doesn't seem like a good way to go for a browser that could be any size.

Alternatively, can these values be set as the resolution (like 1920x1080) and then just use css to strech the game across the entire screen, or is this not the way to go?


In the future I want to make the game resize when the browser re-sizes as well, so I will be adding the same code to the resize event.

You have to use platform specific code...

return new GwtApplicationConfiguration(Window.getClientWidth(), Window.getClientHeight());

source: LibGDX Automatically Scaling GWT Window to Monitor Resolution

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM