LibGDX自动缩放GWT窗口以监视分辨率 [英] LibGDX Automatically Scaling GWT Window to Monitor Resolution

查看:105
本文介绍了LibGDX自动缩放GWT窗口以监视分辨率的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在用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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆