Search code examples
androidlibgdxresolution

resolution independent graphics for Android games


I'm developing an Android game using libgdx and define the virtual camera width/height to be: 800x1280.

I have 3 test devices:

  1. Nexus 5 1920 x 1080 display (445 ppi)
  2. Nexus S 480 x 800 pixels (233 ppi)
  3. Nexus 10 2560 x 1600 (300 ppi)

I'm using GIMP to develop the graphics. How do I pick a appropriate size in GIMP for sprites, coins and background picture so it won't be displayed pixelated? I don't just want to pick a extremely high resolution and increase the app size unnecessary. Would all graphics have to be a power of 2?


Solution

  • If you use OpenGLES1.x, yes the textures must be power of 2. If you use OpenGLES2.0, then they aren't forced to, but some devices do not support them anyways.

    It is recommended you always use power of 2 textures. Try to get all the images in big atlases (1024x1024 for example). That will give you very big performance increase.

    Also I would recommend you to make the graphics for the camera viewport that you are already using (800x1280).
    And decide if you want the graphics to be stretched in different screen ratios or having the sprites look the same but change how much of your world every user can see.

    For the first, leave your viewport like that (800x1280) It will stretch automatically.
    For the second, make your longer side fixed and calculate the other side. (or the other way around, it depends on if you want the user to see more or less in horizontal or vertical). Something like this:

    cam = new OrthographicCamera(((float)Gdx.graphics.getWidth()/Gdx.graphics.getHeight())*800, 1280);
    

    I suggest you to make them for 800x1280, and use the Linear filter for the images so they dont look pixelated when stretched/shrinked.

    texture.setFilter(TextureFilter.Linear, TextureFilter.Linear);