You could use Atlas
with TexturePacker2
. You should economize number of used textures for tile rendering (best choose is only one big texure), because SpriteBatch
caches render calls for the same texture.
Place your tiles in some forlder (e.g. tiles/tile-1.png
, tiles/tile-2.png
), and convert them all into altas via batch script:
java -cp /path-to-the/gdx.jar;/path-to-the/gdx-tools.jar com.badlogic.gdx.tools.imagepacker.TexturePacker2 %source_folder%/tiles %destination_folder%/tiles
TexturePacker2
pack all textures that will be found into Atlas
. Now you could load it:
TextureAtlas atlas = new TextureAtlas(Gdx.files.internal("tiles/yourAtlas.atlas"), false);
Now you could get loaded tiles by calling atlas.getRegions()
, or, use Skin
to hold them:
skin.addRegions(atlas);
Now you can simply get the tile (TextureRegion
, not Texture
) by calling:
skin.getRegion("tile-1")
I hope this helps you.