How to use/setup TexturePacker2 libgdx

2019-08-14 04:26发布

问题:

I have a difficulty with texturepacker2 from libgdx. I was trying to create textureAtlas using texturepakcer2 so that I can create animated images. However I could not use

TexturePacker2.process(Input Directory Path", "Output Directory Path", "texture_file");

Because it could not recognize TexturePacker2. Even thought I import gdx-tool.jar file inside libs and also added libraries through Project -> Properties -> Java Build Path -> Libraries -> Add jars, it still cannot resolve nor recognize the gdx-tool.jar.

How can I create texture atlas using TexturePakcer2? I heard there is a way to create using nightly-build from libgdx, how can I do it? When I unzip latest nightly-build there were so many jar, but I could only run setup-ui.

回答1:

There are several ways. I used to take the way of implementing it into my Desktop application. Whenever i start it, the Atlas is generated. (If i changed something in it).

public class Main
{
    public static void main(String[] args)
    {
        LwjglApplicationConfiguration cfg = new LwjglApplicationConfiguration();
        cfg.title = "MyApp";
        cfg.useGL20 = true; 
        cfg.fullscreen = false; 
        // switch for fullscreen
        if (cfg.fullscreen)
        {
            cfg.width = Toolkit.getDefaultToolkit().getScreenSize().width;
            cfg.height = Toolkit.getDefaultToolkit().getScreenSize().height;
        }
        else
        {
            cfg.width = 1280;
            cfg.height = 720;
        }

        cfg.addIcon("data/appiconWindows.png", FileType.Internal); 
        // automatic packing of the textures and images and so on
        Settings settings = new Settings();
        settings.maxWidth = 2048;
        settings.maxHeight = 2048;
        settings.paddingX = 0;
        settings.paddingY = 0;
        TexturePacker2.process(settings, "directory with the files",
                "output dir", "name of Atlas"); //third is outputdir
        new LwjglApplication(new MainClass(), cfg);
    }
}

Dont forget to add the tools lib to the Desktop project. gdx-tools.jar From the nightly or the Stable.

Else you can call it with the console. Like this:

java -cp gdx.jar;extensions/gdx-tools/gdx-tools.jar com.badlogic.gdx.tools.texturepacker.TexturePacker inputDir [outputDir] [packFileName]


回答2:

Use TexturePacker from com.badlogic.gdx.tools.imagepacker.TexturePacker then create a class as below:

public class TextureSetup {

    public static void main(String[] args) {

        //TexturePacker; using default settings
        TexturePacker.Settings packSettings = new TexturePacker.Settings();     

        TexturePacker.process(packSettings, "input-folder", "output-folder", "textures.pack");
    }
}