Crowni Crowni - 6 months ago 27
Java Question

libGDX : desgin game assets according different size screens

I develop and design assets (background, buttons,... etc) of my game, but when I design any asset I don't know which screen size do I design?. Many screen sizes different in Android devices or

iOS
devices. So, if I start design with largest screen, other devices screen's dimensions will be not good and the assets will be too heavy on old devices, and vice if I start design with small screen, other devices screen will be low resolution (if I used for example
StrecthViewport
).

for example:

stage = new Stage(new StretchViewport(480, 800));


this line on Galaxy note 3 (1080 x 1920) is low resolution

Is there standard designing for the game assets?

Anyone can help me ?

Answer

Well there are many ways to achieve your goal. It depends a lot on the game you create so I can give you only a brief overview what works for me:

Create your assets bigger than the biggest screen you support. F.e. you support 2560x1600 then go with something like 3200x2000.

Create a TextureAtlas for each TEXTURE_SIZE you support. Smartphones have a MAX_TEXTURE_SIZE you can load into the memory. Its usually 1024x1024, 2048x2048, 4096x4096 (Newer phones and desktop graphic cards might even support even more like 8192x8192 or bigger) I create then 3 TextureAtlas: 4096 with 1:1 scaling, 2048 scaled bei 50%, 1024 scaled by 25%.

On the devices read the MAX_TEXTURE_SIZE, this snippet can do that.

public final static int maxTextureSize() {
        /**
         * See http://lwjgl.org/forum/index.php?topic=1314.0;wap2
         */
        IntBuffer max = BufferUtils.newIntBuffer(16);
        max.clear();
        Gdx.gl.glGetIntegerv(GL20.GL_MAX_TEXTURE_SIZE, max);
        return max.get(0);
    }

Then load the TextureAtlas based on the support MAX_TEXTURE_SIZE.

You can even go further. Just some ideas:

  • you can calculate the perfect Texel size for the current device and repack an TextureAtlas having 1:1 screen pixel fitting asset pixel. Then load from that atlas.

  • Some devices may accept an 4096 texture size but their screen is very small so the 2048 version might work aswell, then load the smaller one.