为什么纹理打包器找不到精灵?

时间:2016-12-12 16:24:15

标签: libgdx texturepacker

我使用LibGDX实现的TexturePacker来加载我的精灵。 但是由于某种原因,找不到文件,它给了我这个例外:

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

此代码导致错误:

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
}

我在另一个项目中也得到了完全相同的代码,它运行得很好。我还没有发现项目属性有任何差异。

1 个答案:

答案 0 :(得分:0)

确保精灵实际存在于该目录中。

听起来很光顾,但我遇到了同样的问题,对我来说,我的桌面项目中的资产目录被误导了#34;链接文件夹"这实际上只是对我的核心项目的资产文件夹的引用。所以在eclipse中,文件夹就在那里,看起来应该没有问题,但是通过浏览Windows文件浏览器,很明显文件实际上并不存在于该位置。

我的修复是将输入和输出更改为后退并检查核心目录而不是桌面。

所以而不是:

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

以下方法可行:

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

现在我不知道您的确切设置,但考虑到您的代码在另一个项目中工作,我会打赌另一个项目的资产实际存储在桌面目录中,因为这个图像将图像存储在核心目录中