Search code examples
androidlibgdx

Libgdx - texture packer


I've got a game where at start-up it creates all the needed objects (so about 600 Sprites of the same texture, 1 player texture and about 100 Sprites of the same texture again). So only 3 texture's needed.

Those texture's are currently each in their own .png file.

Should I pack those 3 into a texture atlas. Because I am reusing a sprite like 600 hundred times and another one just 1 time. Would it be maybe slower?


Solution

  • TextureAtlas is not about reusing asset - it is about file access performance improvement. When you have your 3 .png files the engine needs to load them separately what means that it need to define FileHandler threetime, call memory three times and so on. Using TextureAtlas you need to load graphics from memory just once which is definitely more efficient.

    The second thing about why to use TextureAtlas is that the texture is loaded also just once to GPU when if you would be using separate Texture they would need to be loaded one by one.

    So the answer is - yes you should use TextureAtlas however it would not make a difference due to what you are asking about. It does not matter if you are rendering 1, 2 or 1000 same sprites if you are using the same Texture - performance will be the same no matter if you are using TextureAtlas or not.


    On this step you should also read about AssetManager to know how to deal with assets in LibGDX