Reputation: 3205
I have a libgdx project that uses AssetManager to load the resources like so:
for (FileHandle f : Gdx.files.internal("textures").list("png") ) {
assetManager.load(f.toString(), Texture.class);
System.out.println("Asset queued for loading: " + f.toString());
}
assetManager.finishLoading();
System.out.println("Loaded assets: " + assetManager.getLoadedAssets());
This works fine when I run the desktop launcher, but it fails when I deploy it to html5 with the message:
GwtApplication: exception: Asset not loaded: textures/rifleman_walking.png
Asset not loaded: textures/rifleman_walking.png
I've doubledchecked the filenames, just to make sure there wasn't something as stupid as a typo on my end. I'm also a bit thrown off by the fact that it only seems to affect the html5 version. When I look at the assets/ directory in the project webroot, it does contain everything as referenced in the code.
Note that my code worked fine for both desktop and html5 before having AssetManager
load textures, instead of loading the textures manually via hardcoded filenames.
My theories:
I got the exact same error for the exact same file when I forgot to include assetManager.finishLoading();
, so I'm wondering if there's something special about the html5 deployment that requires a workaround.
Additionally, I have loads of debug info that I simply print via System.out.println()
, and I would love to see this in the Gwt text area that now only prints the error upon start. How can I enable the output of System.out.println()
in the same window?
After reading around, I found that calling Gdx.app.setLogLevel(Application.LOG_INFO);
in the core launcher is the way to go, but it doesn't seem to change anything. If I was able to see what I print, it would help with the debugging a lot.
Edit: The offending line is this:
protected Texture getAssetTexture(String textureName) {
return world.getPainter().getAssetManager().get(textureName, Texture.class);
}
I've already checked that textureName
is referenced correctly: The file rifleman_walking.png
is residing in the textures
subfolder of assets.
Upvotes: 0
Views: 347
Reputation: 18803
AFAIK, LibGDX pre-loads all assets before starting in HTML mode (because it's impossible to access images synchronously in JS otherwise). So my guess (without seeing the actual code) would be that you try to load assets before LibGDX is ready.
Don't get me started on System.out.println() in GWT. The simplest thing to see debug output is to call the corresponding LibGDX log function.
Upvotes: 1