3

So in my game i have more than 32000 images (size: 32x32). How to store this amount of images? What could better: loading these images as separate files or as one big texture atlas?

Dragomirus
  • 439
  • 3
  • 14

1 Answers1

8

When you load a texture (image) in your game by doing you load a texture in GPU.

So let's say you have 3200 images and you load them separately that means 3200 textures loaded on the GPU. That's harsh and will eat loads of memory.

Now let me explain what is TextureRegion

TextureRegion, takes an area from the Texture according to the dimension you provide, the advantage of having it is that you don't have to load textures again and again and the bigger advantage is you don't have to load each and every texture on GPU as you can do it directly by loading one big texture and extracting sub regions(TextureRegions) from it.

Now because you want to use TextureRegions, it will be hard to know the dimensions of each and every sub image to load them from Texture Sheet. So what we do is we pack the Textures into a bigger Texture using TexturePacker(an application) which then creates a .pack file. It will pack every texture into one image AND create a .pack file. Now when you load the .pack file, it is loaded using TextureAtlas class For example imagine a pokemon pack file which has all the pokemons into it.

 TextureAtlas  pokemonFrontAtlas = new TextureAtlas(Gdx.files.internal("pokemon//pokemon.pack"));

Now you packed 3200 files using Texture Packer and you want to load a image(Texture) which has file name as "SomePokemon".

Now to get a particular TextureRegion from it, you do

pokemonFrontAtlas.findRegion("SomePokemon")

findRegion(String name) returns you the textureRegion from the TextureAtlas.

A TextureAtlas class contains a collection of AtlasRegion class which extends TextureRegion class.

See Javadocs for more details TextureAtlas

Sneh
  • 3,527
  • 2
  • 19
  • 37
  • Okey but i dont understand one last thing. Is this whole texture atlas will be in my memory or just a part which ive loaded to textures ☺? – Dragomirus Jan 17 '16 at 20:38
  • When you load a texture atlas, its still loaded into the memory but only one texture will be created however if you load many textures you are effectively loading many textures on gpu. – Sneh Jan 17 '16 at 20:46
  • And is there another way to pack my textures into one file and only load these textutres into memory and then to gpu which im current using via asset manager ☺? – Dragomirus Jan 17 '16 at 21:00
  • Firstly since you have 3200 images, it won't be more than 1 image atlas which will be generated (depending on how many image texture packer can fit in one atlas). What I would do is load these texture atlas onto GPU whenever you need to load a image part of the atlas. I don't know any other way sorry. :/ – Sneh Jan 17 '16 at 21:05