libGDX create and use tileset with Texture Packer

Download
GDX Texture Packer

Make sure you have Java installed.

Open CMD where you have downloaded the gdx-texturepacker.jar.

Launch it.

Program is opened.

gdxtexturepacker

Prepare your images. Eg. Create a folder containing few images. Mine are three 64×64 png with alpha (32bit).

folder_cogs

In program create “New pack”, name it, eg. “mycogs”.

Browse “Input directory”, eg. “C:\Users\Roman\Pictures\cogs”. Same for “Output directory”.

Press “Pack’em all”. Console shows up showing progress. And Done!

gdxtextureprocesing

2 files are generated in output directory: “mycogs.png” the tileset/atlas with all images and “mycogs.pack” the text file with description which image is where, etc.

cogs_atlas

Now, lets use them in our libGDX project. Move those two files to your project folder.

import com.badlogic.gdx.graphics.g2d.TextureAtlas;
import com.badlogic.gdx.graphics.g2d.TextureAtlas.AtlasRegion;

TextureAtlas ta = new TextureAtlas("mycogs.pack");
AtlasRegion cogTex = ta.findRegion("cog_red");
AtlasRegion cogNTex = ta.findRegion("cog_white");
AtlasRegion cogSTex = ta.findRegion("cog_grey");

libGDX docs about TextureAtlas, AtlasRegion.

Posted in Blog Tagged with: ,

Leave a Reply

Your email address will not be published. Required fields are marked *

*