User3
User3

Reputation: 2535

libGDX create an atlas out of a folder of images

I am following a tutorial at Game from Scratch

I am confused at the following:

java -cp gdx.jar;extensions/gdx-tools/gdx-tools.jar com.badlogic.gdx.tools.imagepacker.TexturePacker2 c:\tmp c:\tmp spritesheet tmp

I have a required folder with images how do I convert it into an atlas?

This question might sound feeble, I am just a beginner. Any help would be great :)

Upvotes: 2

Views: 3189

Answers (2)

plastique
plastique

Reputation: 1204

Place all images you want to be in final atlas in one folder and its subfolders. Create pack.json file with configuration in the folder and each subfolder (optional step). Run following code (save it into MyPacker.java file) :

import com.badlogic.gdx.tools.texturepacker.TexturePacker;
public class MyPacker {
   public static void main (String[] args) throws Exception {
       TexturePacker.process(inputDir, outputDir, packFileName);
 }
}

It may take a some time (seconds or even minutes) to finish. The process may result in more than one texture atlases. Please note that not only picture altas will be created but also a *.atlas file describing content of the atlas.

Created atlas can be used as source of textures following way: extureAtlas atlas;

TextureAtlas atlas = new TextureAtlas(Gdx.files.internal("packedimages/pack.atlas"));
AtlasRegion region = atlas.findRegion("imagename");
Sprite sprite = atlas.createSprite("otherimagename");

Please read the current documentation to see other options and details about pack.json configuration files.

Upvotes: 3

Nanoc
Nanoc

Reputation: 2381

Try the GUI version of texturepacker, its quite simple to use.

https://code.google.com/p/libgdx-texturepacker-gui/

Hope this helps.

Upvotes: 2

Related Questions