Android libgdx 大屏幕分辨率

发布于 2024-11-07 03:32:39 字数 418 浏览 0 评论 0原文

我如何支持(制定算法)libgdx以支持多种屏幕分辨率?我使用 if 语句使我的应用程序在 HTC Tattoo 上运行,参数如下:

if (Gdx.input.getX()==40) {

在更大的屏幕上运行该应用程序的好算法是什么? 我尝试了这个,但没有任何结果:

publis static int translatex() {
     float p = (float)Gdx.graphics.getHeight()*340;
     return (int) p*Gdx.input.getX();
}

340 是我在 HTC Tattoo 上使用的基本 x(我手机上的 x 分辨率)。 那么......我怎样才能制作一个支持绝对值大屏幕的函数。我不想改变 if 语句。

How can I support (make an algorithm) for libgdx for supporting multiple screen resolution? I made my app work on HTC Tattoo using if statments with parameters like:

if (Gdx.input.getX()==40) {

What is a good algorithm for making this work on bigger screens?
I tried this but without any result:

publis static int translatex() {
     float p = (float)Gdx.graphics.getHeight()*340;
     return (int) p*Gdx.input.getX();
}

340 is the base x (the x resolution on my phone) used by me on the HTC Tattoo.
So.....how can I make a function for supporting big screens with absolute values. I don`t want to change the if-statements.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

埖埖迣鎅 2024-11-14 03:32:39

这很容易。您基本上是根据原始分辨率构建整个程序,但是在处理定位和纹理大小的所有内容中都有这样的事情:

private void resize()
{
    float x = Gdx.graphics.getWidth();
    float y = Gdx.graphics.getHeight();

    float changeX = x / assumeX; //being your screen size that you're developing with
    float changeY = y / assumeY;

    position = new Vector2(position.x * changeX, position.y * changeY);
    width = startWidth * changeX;
    height = startHeight * changeY;
    bounds = new Vector2 (position.x, (Gdx.graphics.getHeight() - position.y) - height);

}

基本上您正在做的就是获取生成的每个对象并通过根据变化而增加/减少的东西来运行它分辨率中的 x/y 值。距离本地越远,它就越大。当检查某处的某物或将某物放置在某处时,始终将其编码为您想要的分辨率,但在显示它或让它与程序的其余部分交互之前通过调整大小函数运行它。

It's pretty easy. You basically build your entire program for your native resolution, but in everything dealing with positioning and texture sizing have something like this:

private void resize()
{
    float x = Gdx.graphics.getWidth();
    float y = Gdx.graphics.getHeight();

    float changeX = x / assumeX; //being your screen size that you're developing with
    float changeY = y / assumeY;

    position = new Vector2(position.x * changeX, position.y * changeY);
    width = startWidth * changeX;
    height = startHeight * changeY;
    bounds = new Vector2 (position.x, (Gdx.graphics.getHeight() - position.y) - height);

}

Basically what you're doing is taking every object generated and running it through something that increases/decreases depending on the change in the x/y values in your resolution. The further it is from the native, the bigger it will be. When checking of something is somewhere or putting something somewhere, always code it as your desired resolution but run it through a resize function before displaying it or letting it interact with the rest of your program.

宛菡 2024-11-14 03:32:39

http://www.java-gaming.org/index 查看更优雅的解决方案.php?topic=25685.0(另请参阅 Nate 对该解决方案的评论)。

另外,如果您使用 scene2d,请注意当前(libgdx 0.9.6)stage.setViewport 方法应该具有此功能,但它的行为并不像人们预期的那样。

更新: setViewPort 已修复,因此可以按预期工作。

See a more elegant solution at http://www.java-gaming.org/index.php?topic=25685.0 (also see Nate's comment to that solution).

Also, if you use scene2d, note that currently (libgdx 0.9.6) stage.setViewport method should have this functionality, but it doesn't really behave as one would expect.

Update: setViewPort was fixed, so this works just as expected.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文