Is this how one properly loads a texture into an AssetManager
?
Texture tex;
AssetManager manager = new AssetManager();
manager.load("menu/bg.png",Texture.class);
tex = manager.get("menu/bg.png",Texture.class);
The texture fails to load with error "cannot load the texture menu/bg.png".
How should we load our texture using the AssetManager
?
This is almost how the AssetManager should be used, but not entirely. I recommend reading on the wiki about the libgdx AssetManager.
Some points:
The variable should be in camelCase, so AssetManager manager... instead of AssetManager Manager.
You will need to call manager.update()
; to actually make it load stuff. This will need to be called until manager.update()
; returns true, then it's done loading. So you can make a loading screen where you call manager.update();
each frame, and when it returns true you switch to some other screen.
If you just want everything to load, and block until it's loaded, call manager.finishLoading();
before trying to get anything from the manager.
You may have to create a folder in the assets
folder named data
and put your assets there instead of putting them directly in the assets folder. So put your assets in mygame-android\assets\data
instead of mygame-android\assets
.
If you're using the gdx-setup-gui to create your project, you should be fine. But if not, your desktop project will need to know where to find the assets as well.
An example on how to create an animated, responsive loading screen with libgdx. (video)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With