-
Notifications
You must be signed in to change notification settings - Fork 1
Asset Management
Asset Management has been taken to the next level in braingdx. On an average gamejam, developers do spend quite some time on setting up assets and accessing them via the AssetManager in libgdx. However, this can introduce lots of boilerplate code, since you have to load all your assets in beforehand. This is where a so called GameAssetLoader
comes into play:
public class MyAssetLoader implements GameAssetLoader {
@Override
public void put(Map<String, Class<?>> map) {
map.put("player.png", Texture.class);
}
}
braingdx will automatically pick up the assets defined and load them for you. Make sure to provide your asset loader within the BrainGdxGame
class:
public class MyGame extends BrainGdxGame {
@Override
protected GameAssetLoader getAssetLoader() {
return new MyAssetLoader();
}
/** rest of the class **/
}
The current approach allows us to automate things where needed. As a developer on a game jam I do not want to care about registering my assets. Ideally, the workflow should look like this:
- move asset into
/assets
folder - define asset constant
- use your asset straight away This is possible with the so called SmartAssetLoader introduced in 0.1.0.
Create a new interface called Assets
which looks like this:
public interface Assets {
interface Textures {
String PLAYER = "player.png";
}
}
After doing that you simply enable smart asset loading within your BrainGdxGame
class:
public class MyGame extends BrainGdxGame {
@Override
protected GameAssetLoader getAssetLoader() {
return new SmartAssetLoader(Assets.class);
}
/** rest of the class **/
}
braingdx will automatically pick up your assets and load them respectively. braingdx knows how to translate assets into Java objects (e.g. Texture, Music, Sound, TiledMap) by scanning the name of the sub-interface in your Assets
interface.
The following configuration is provided by default:
Interface Name | LibGdx Class | Notes |
---|---|---|
Sounds | Sound | |
Musics | Music | |
BitmapFonts | BitmapFont | |
Fonts | FreeTypeFontGenerator | *depends on Freetype |
Particles | ParticleEffect | |
TiledMaps | TiledMap |
The configuration can be changed or extended by providing it on initialization:
public class MyGame extends BrainGdxGame {
@Override
protected GameAssetLoader getAssetLoader() {
SmartAssetLoaderConfiguration config = SmartAssetLoader.defaultConfiguration();
config.getClassMapping.put("CustomType", Custom.class);
// Make sure to register the loading of this new asset
SharedAssetManager.getInstance().register(Custom.class, new CustomLoader(SharedAssetManager.fileHandleResolver));
return new SmartAssetLoader(Assets.class, config);
}
/** rest of the class **/
}
Read more on this article how to register custom assets in libgdx.