2016-12-12 66 views
0

我使用由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 
} 

我也有在其他項目完全相同的代碼和它工作得很好。我還沒有發現項目屬性有任何差異。

+0

您是否將輸入精靈複製到C:\ Users \ Kontor \ Desktop \ Codeporn \ LibGDX-workspace \ OneRoom \ desktop \ sprite \ input? – Hllink

+0

工作目錄必須設置爲運行配置中包含'sprites /'的目錄。 – Tenfour04

回答

0

確保精靈實際上存在於該目錄中。

聲音光顧,但我有同樣的問題,對我來說,我被我的桌面項目中的資產目錄誤導爲「鏈接文件夾」,實際上這只是對我的核心項目的資產文件夾的引用。所以在日食文件夾在那裏,看起來應該沒有問題,但通過Windows文件瀏覽器看,很明顯,該文件實際上並不存在於該位置。

我的修復方法是更改​​輸入和輸出回退並檢查覈心目錄而不是桌面。

所以不是:

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

以下將工作:

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

現在,我不知道您的具體設置,但考慮到你的代碼在不同的項目中,我敢打賭,工作原理其他項目的資產實際上存儲在桌面目錄中,因爲此人將圖像存儲在覈心目錄中。