0
votes

Im using the TexturePacker implemented by LibGDX to load my sprites. For some reason however, the files are not found and it gives me this exception:

Exception in thread "main" java.lang.RuntimeException: Error packing images.
at com.badlogic.gdx.tools.texturepacker.TexturePacker.process(TexturePacker.java:620)
at com.zebleck.OneRoom.desktop.DesktopLauncher.processSprites(DesktopLauncher.java:35)
at com.zebleck.OneRoom.desktop.DesktopLauncher.main(DesktopLauncher.java:17)
Caused by: java.lang.IllegalArgumentException: Input file does not exist: C:\Users\Kontor\Desktop\Codeporn\LibGDX-workspace\OneRoom\desktop\sprites\input
at com.badlogic.gdx.tools.FileProcessor.process(FileProcessor.java:117)
at com.badlogic.gdx.tools.texturepacker.TexturePackerFileProcessor.process(TexturePackerFileProcessor.java:70)
at com.badlogic.gdx.tools.texturepacker.TexturePacker.process(TexturePacker.java:618)
... 2 more

This code is causing the error:

public static void main (String[] arg) {
    LwjglApplicationConfiguration config = new LwjglApplicationConfiguration();
    config.width = 800;
    config.height = 800;

    deleteFiles();
    processSprites();

    new LwjglApplication(new OneRoom(), config);
}

public static void deleteFiles() {
    File outputDir = new File("../android/assets/sprites/output");
    File[] listFiles = outputDir.listFiles();
    if (listFiles != null && listFiles.length > 0) {                
        for (File file : listFiles) {
            file.delete();
        }
    }
}

public static void processSprites() {
    TexturePacker.Settings settings = new TexturePacker.Settings();
    //System.out.println(Gdx.files.internal("sprites/input/player.png").toString());
    TexturePacker.process(settings, "sprites/input", "sprites/output", "pack"); // THIS LINE CAUSES THE ERROR
}

I also got the EXACT same code in another project and it works just fine. I haven't found any differences in the project properties yet.

1
did you copy your input sprites to C:\Users\Kontor\Desktop\Codeporn\LibGDX-workspace\OneRoom\desktop\sprites\input ?Hllink
The working directory must be set to the one that contains sprites/ in your run configuration.Tenfour04

1 Answers

0
votes

Make sure the sprites actually exist in that directory.

Sounds patronising but I was having the same issue and for me I was being misled by my assets directory in my desktop project being a "Linked Folder" that was actually just a reference to the assets folder of my core project. So in eclipse the folder is there and looks like there should be no problem but looking through windows file explorer it was clear the files didn't actually exist at that location.

My fix was to change the input and output to step back and check the core directory instead of the desktop.

So instead of:

TexturePacker.process(settings, "sprites/input", "sprites/output", "pack");

The following would work:

TexturePacker.process(settings, "../core/sprites/input", "../core/sprites/output", "pack");

Now I don't know your exact setup but considering your code works in a different project I would wager that the other project has the assets actually stored in the desktop directory where as this one stores the images in the core directory.