I'm using the AssetManager in libgdx with an Atlas file, to load all textures. This works just fine, however I want to modify the code I have to incorporate using different textures.
For example when fully zoomed out, I don't need a nice hi-res texture. A small pixelated dot will suffice. When zoomed in, I want to use the proper hi-res texture.
Currently I have this:
main render() method:
batch.draw(Assets.instance.ballsmall.ballsmall, this.x, this.y);
(you can ignore the double ballsmall.ballsmall
for the time being. That's just a smaller semantic issue with my asset object structure.)
AssetManager section:
public class Assets implements Disposable {
private AssetManager _assetManager;
public BallSmall ballsmall;
public static final Assets instance = new Assets();
private Assets() {}
public void init(AssetManager assetManager)
{
_assetManager = assetManager;
_assetManager.load("output/Game.atlas", TextureAtlas.class);
_assetManager.finishLoading();
TextureAtlas atlas = _assetManager.get("output/Game.atlas");
for (Texture t : atlas.getTextures())
{
t.setFilter(TextureFilter.Linear, TextureFilter.Linear);
}
ballsmall = new BallSmall(atlas);
}
@Override
public void dispose() {
_assetManager.dispose();
}
public class BallSmall {
public final AtlasRegion ballsmall;
public BallSmall(TextureAtlas atlas) {
ballsmall = atlas.findRegion("ballsmall");
}
}
}
I want to keep the main render()
method to be simple like that, calling for an Assets.instance
and possibly passing in the global zoom level as a parameter. However the AssetManager must then use this zoom level to determine which texture to swap. Many thanks.