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

问题描述

我如何支持(使一个算法)的libgdx支持多屏幕分辨率?

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是宏达纹身我所用的基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.

推荐答案

这是pretty的方便。你基本上构建你的整个程序的原始分辨率,但一切都处理的定位和纹理大小是这样的:

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值的变化在你的分辨率。进一步的是从天然的,更大的将。东西当检查是什么地方,或者把一些地方,总是$ C C $它作为你想要的分辨率,但通过调整大小功能显示,或让它与你的程序的其他部分交互,然后运行它。

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