简体   繁体   English

如何使LibGDX应用程序以与浏览器框架相同的分辨率启动

[英]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. 在我的HTML启动器代码中,我必须为其输入宽度和高度,因此我一直在尝试访问浏览器框架的宽度和高度来初始化游戏。 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() Gdx.graphics.getWidth()Gdx.graphics.getHeight()
  2. Gdx.app.getGraphics().getWidth() and Gdx.app.getGraphics().getHeight() Gdx.app.getGraphics().getWidth()Gdx.app.getGraphics().getHeight()
  3. this.getGraphics().getWidth() and this.getGraphics().getHeight() this.getGraphics().getWidth()this.getGraphics().getHeight()

All of these when used on this code: return new GwtApplicationConfiguration(int width, int height); 在此代码上使用所有这些方法: 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? 或者,是否可以将这些值设置为分辨率(例如1920x1080),然后仅使用CSS在整个屏幕上拉动游戏,或者这不是可行的方法吗?


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 来源: LibGDX自动缩放GWT窗口以监视分辨率

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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