问题
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();
}
}
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)
回答1:
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());
来源:https://stackoverflow.com/questions/33618342/libgdx-automatically-scaling-gwt-window-to-monitor-resolution