Android large screen resolution for Android libgdx

How can I support (make an algorithm) for libgdx to support multiple screen resolution? I made an application for working with HTC Tattoo using statuses with parameters such as:

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

What is a good algorithm for working on large screens? I tried this, but without any results:

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

340 is the base x (x resolution on my phone) used by me on HTC Tattoo. So, how can I make a function to support large screens with absolute values. I do not want to change if-statements.

+4
source share
2 answers

This is pretty easy. You basically build your entire program for your own resolution, but there is something like this about everything about positioning and resizing textures:

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

Essentially, you take each generated object and run it through something that increases / decreases depending on the change in x / y values ​​in your resolution. The farther from the native, the more will be. When you check something somewhere or put something somewhere, always encode it as the desired resolution, but pass it through the resize function before displaying it or allowing it to interact with the rest of your program.

+14
source

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

Also, if you are using scene2d , note that the stage.setViewport (libgdx 0.9.6) stage.setViewport should have this function at the moment, but it doesn't actually behave as you would expect.

Update: setViewPort has been fixed, so it works as expected.

+3
source

All Articles