LibGDX自动缩放GWT窗口以监视分辨率 [英] LibGDX Automatically Scaling GWT Window to Monitor Resolution
问题描述
我正在用LibGDX创建一个应用程序,并将其专门部署到GWT HTML5环境中.以下代码按预期设置了1280x720分辨率的环境:
I'm creating an application with LibGDX and deploying exclusively to a GWT HTML5 environment. The below code sets up my environment with a 1280x720 resolution as expected:
public class HtmlLauncher extends GwtApplication {
@Override
public GwtApplicationConfiguration getConfig() {
return new GwtApplicationConfiguration(1280, 720); // <-- here is line of code in question
}
@Override
public ApplicationListener getApplicationListener() {
return Engine.getInstance();
}
}
我希望在加载时动态调整应用程序的大小,使其实质上是全屏"(填满整个浏览器空间),而不是固定的1280x720.在不特别了解客户端的监视器大小的情况下,如何实现此行为? (Gdx.graphics.getWidth()和Gdx.graphics.getHeight()返回NPE,因为我相信getConfig()会初始化它们)
I would like my application to be dynamically sized at load-time as essentially "full screen" (filling up the entire browser space), and not a fixed 1280x720. How can I achieve this behavior without knowing specifically the client's monitor size? (Gdx.graphics.getWidth() and Gdx.graphics.getHeight() return NPE as I believe getConfig() initializes them)
推荐答案
您将必须使用平台特定的代码来完成此操作.对于GWT,这似乎是
You will have to do this with platform specific code. In case of GWT, this seems to be Window
.
return new GwtApplicationConfiguration(Window.getClientWidth(), Window.getClientHeight());
这篇关于LibGDX自动缩放GWT窗口以监视分辨率的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!