LibGDX 自动缩放 GWT Window 以监控分辨率
LibGDX Automatically Scaling GWT Window to Monitor Resolution
我正在使用 LibGDX 创建应用程序并专门部署到 GWT HTML5 环境。下面的代码按预期设置了 1280x720 分辨率的环境:
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();
}
}
我希望我的应用程序在加载时动态调整大小,基本上 "full screen"(填满整个浏览器 space),而不是固定的 1280x720。在不知道客户端显示器尺寸的情况下如何实现这种行为? (Gdx.graphics.getWidth() 和 Gdx.graphics.getHeight() return NPE 因为我相信 getConfig() 会初始化它们)
您必须使用特定于平台的代码来执行此操作。对于 GWT,这似乎是 Window
.
return new GwtApplicationConfiguration(Window.getClientWidth(), Window.getClientHeight());
我正在使用 LibGDX 创建应用程序并专门部署到 GWT HTML5 环境。下面的代码按预期设置了 1280x720 分辨率的环境:
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();
}
}
我希望我的应用程序在加载时动态调整大小,基本上 "full screen"(填满整个浏览器 space),而不是固定的 1280x720。在不知道客户端显示器尺寸的情况下如何实现这种行为? (Gdx.graphics.getWidth() 和 Gdx.graphics.getHeight() return NPE 因为我相信 getConfig() 会初始化它们)
您必须使用特定于平台的代码来执行此操作。对于 GWT,这似乎是 Window
.
return new GwtApplicationConfiguration(Window.getClientWidth(), Window.getClientHeight());