LibGdx: packing textures, creating .atlas file

When I first started on my quest to create an .atlas file from my resources, I got lost… quickly. The main reason being that when you google “TexturePacker”, the top results are not the texturepacker that works with LibGdx.

Instead, LibGdx comes with its own flavor of a texturepacker. I have found that it’s easiest to create an eclipse project that creates the .atlas file which I run each time I update my image resources. Like so:

  1. Create a new Gradle Project in eclipse. Name it something like MyProject-texturepacker and put it in the MyProject/texturepacker folder
  2. Copy the build.gradle file from the desktop project to the texturepacker project
  3. You can remove some of the wierd src folders (i.e. src/java/ src/main/java etc.) if you want and add a normal src folder
  4. Add a main class to your project. I called mine TexturePackerRunner
  5. Edit the build.gradle file in your new project change the project.ext.mainclassname to the classpath of your main class. i.e.
                    project.ext.mainClassName = "com.gigagrand.myproject.texturepacker.TexturePackerRunner"

    On about line 32 make sure you change

            name = appName + "-desktop"


            name = appName + "-texturepacker"
  6. Now goto the build.gradle file in your root MyProject folder and add the lines
                      apply plugin: "java"
                      dependencies {
                               compile "com.badlogicgames.gdx:gdx:$gdxVersion"
                               compile "com.badlogicgames.gdx:gdx-tools:$gdxVersion"
  7. Edit the settings.gradle file in the root project to include your new project
             include 'desktop', 'android', 'ios', 'html', 'core', 'texturepacker'
  8. You may notice that your new texturepacker folder is showing up in the root project. How Annoying! Edit the root .project file and silence it by adding

    to the other matchers in the file.

  9. Now your project should be setup. Right click on your new project and goto Gradle->Refresh All to let gradle rebuild the dependencies
  10. And for the actual project. Create a textures and an output folder in your texturepacker project
  11. In your TexturePacker class
             package com.gigagrand.myproject.texturepacker;
             public class TexturePackerRunner
             	public static void main(String[] args)
                        String projectPath = System.getProperty("user.dir");
                        String inputDir = projectPath + "\\resources";
                        String outputDir = projectPath + "\\output";
                        String packFileName = "skinname";

The result will be a generated .atlas and .png file in the outputDir.

One thought on “LibGdx: packing textures, creating .atlas file

  1. Hi
    Thanks a lot for this solution. Been groping in the dark for sometime until you saved the day!
    Thanks a lot, again. 🙂

Leave a Reply

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