本文介绍了Android libgdx 大屏分辨率的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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 是我在 HTC Tattoo 上使用的基本 x(我手机上的 x 分辨率).那么.....我怎样才能制作一个支持具有绝对值的大屏幕的功能.我不想更改 if 语句.

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.

推荐答案

很简单.你基本上是为你的原始分辨率构建你的整个程序,但是在处理定位和纹理大小的所有事情中都有这样的东西:

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);

}

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

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.

这篇关于Android libgdx 大屏分辨率的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-05 15:55