Reputation: 853
I'm currently reading a book on LibGDX Game Development - Learning LigbGDX Game Development. In the book, we use TexturePacker2 to generate a .png and .pack file to pack a half dozen textures into a texture atlas. I followed the code exactly, but it does not generate anything into the destination folder. Here is the code in my desktop project folder:
package com.packtpub.libgdx.canyonbunny;
import com.badlogic.gdx.backends.lwjgl.LwjglApplication;
import com.badlogic.gdx.backends.lwjgl.LwjglApplicationConfiguration;
import com.badlogic.gdx.tools.imagepacker.TexturePacker2;
import com.badlogic.gdx.tools.imagepacker.TexturePacker2.Settings;
public class Main {
private static boolean rebuildAtlas = true;
private static boolean drawDebugOutline = false;
public static void main (String[] args) {
if (rebuildAtlas) {
Settings settings = new Settings();
settings.maxWidth = 1024;
settings.maxHeight = 1024;
settings.debug = drawDebugOutline;
TexturePacker2.process(settings, "assets-raw/images", "../CanyonBunny-android/assets/images", "canyonbunny.pack");
TexturePacker2.process(settings, "assets-raw/images-ui", "../CanyonBunny-android/assets/images", "canyonbunny-ui.pack");
rebuildAtlas = false;
}
LwjglApplicationConfiguration cfg = new LwjglApplicationConfiguration();
cfg.title = "CanyonBunny";
cfg.useGL20 = false;
cfg.width = 800;
cfg.height = 480;
new LwjglApplication(new CanyonBunnyMain(), cfg);
}
}
But when I run this, nothing is generated into my CanyonBunny-android/assets/images folder. The only way I can get my textures to load is to download the sources for the book and put the already generated .png and .pack folder in the correct folder. I followed the book exactly, so I'm not sure what the issue is. I get the logging message that it is generating a 1024x1024 texture atlas, so the code is being executed. Is there something I'm missing?
Here is what the console says when I start the application(with the already-generated files)
Packing.........
Writing 1024x1024: ../CanyonBunny-android/assets/images/canyonbunny.png
Packing......
Writing 1024x1024: ../CanyonBunny-android/assets/images/canyonbunny-ui.png
game.Assets: # of assets loaded: 2
game.Assets: asset: images/canyonbunny.pack
game.Assets: asset: images/canyonbunny.png
Without the already-generated files:
Packing.........
Writing 1024x1024: ../CanyonBunny-android/assets/images/canyonbunny.png
Packing......
Writing 1024x1024: ../CanyonBunny-android/assets/images/canyonbunny-ui.png
game.Assets: Couldn't load asset 'images/canyonbunny.pack'
com.badlogic.gdx.utils.GdxRuntimeException: File not found: images/canyonbunny.pack (Internal)
at com.badlogic.gdx.files.FileHandle.read(FileHandle.java:127)
at com.badlogic.gdx.graphics.g2d.TextureAtlas$TextureAtlasData.<init>(TextureAtlas.java:97)
at com.badlogic.gdx.assets.loaders.TextureAtlasLoader.getDependencies(TextureAtlasLoader.java:59)
at com.badlogic.gdx.assets.loaders.TextureAtlasLoader.getDependencies(TextureAtlasLoader.java:34)
at com.badlogic.gdx.assets.AssetLoadingTask.handleSyncLoader(AssetLoadingTask.java:103)
at com.badlogic.gdx.assets.AssetLoadingTask.update(AssetLoadingTask.java:92)
at com.badlogic.gdx.assets.AssetManager.updateTask(AssetManager.java:399)
at com.badlogic.gdx.assets.AssetManager.update(AssetManager.java:314)
at com.badlogic.gdx.assets.AssetManager.finishLoading(AssetManager.java:337)
at game.Assets.init(Assets.java:38)
at com.packtpub.libgdx.canyonbunny.CanyonBunnyMain.create(CanyonBunnyMain.java:17)
at com.badlogic.gdx.backends.lwjgl.LwjglApplication.mainLoop(LwjglApplication.java:125)
at com.badlogic.gdx.backends.lwjgl.LwjglApplication$1.run(LwjglApplication.java:108)
game.Assets: # of assets loaded: 0
Exception in thread "LWJGL Application" com.badlogic.gdx.utils.GdxRuntimeException: java.lang.NullPointerException
at com.badlogic.gdx.backends.lwjgl.LwjglApplication$1.run(LwjglApplication.java:111)
Caused by: java.lang.NullPointerException
at com.badlogic.gdx.utils.ObjectMap.get(ObjectMap.java:278)
at com.badlogic.gdx.assets.AssetManager.get(AssetManager.java:103)
at game.Assets.init(Assets.java:45)
at com.packtpub.libgdx.canyonbunny.CanyonBunnyMain.create(CanyonBunnyMain.java:17)
at com.badlogic.gdx.backends.lwjgl.LwjglApplication.mainLoop(LwjglApplication.java:125)
at com.badlogic.gdx.backends.lwjgl.LwjglApplication$1.run(LwjglApplication.java:108)
Upvotes: 2
Views: 2287
Reputation: 1
I had the same problem. It worked with drawDebugOutline = true
, but when I changed it to false it crashed.
It is an Eclipse thing...
The solution as hinted at above is to refresh the project. Eclipse is not seeing the new packed texture file until you refresh. Right click on the Android project and click "Refresh" which will cause Eclipse to find the new file.
Upvotes: 0
Reputation: 8138
Looks like you are using an old version of libgdx — right? TexturePacker2
isn't there anymore, there's just the TexturePacker
now (and it works flawlessly, by the way). I'd recommend you updating first.
Upvotes: 2
Reputation: 7057
Check if the files are actually created in the correct folder using file explorer (not eclipse).
If you can't find, try searching it and make it appear in the correct folder first.
The log suggests that the file is being generated, I suppose it should be.
However, eclipse does not recognize the newly generated files. You have to hit refresh in the eclipse project folder before using them.
Check it it works first.
Now you won't be able to pack them at each run. I had the same issue, so I created a different project (to be used as a tool) which would do packing (and automate many other little things). Whenever I changed assets, I'd run the tool once before testing.
Hope this helps.
Good luck.
Upvotes: 4