0

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.

Jammo
  • 1,838
  • 4
  • 25
  • 39
  • Load both `Texture`s, the high res and the low res, and write a getter: `getBallSmall(float zoom) { if (zoom > LOW_RES_ZOOM) return _assetManager.get("HighResTexture"); else return _assetManger.get("LowResTexture"); }` – Robert P Mar 25 '14 at 09:19
  • Yeah, it was rather simple actually. Thanks. However, the texture doesn't swap until the program has focus again, or I'm stepping through the debugger. – Jammo Mar 25 '14 at 11:00
  • Actually, this might be worth having as a separate question, but is there any performance-benefit to swapping the texture if fully zoomed-out? Using a different image from the atlas, if the same dimensions (say, 64x64 8bit PNG) wouldn't have any benefit as far as I can see? – Jammo Mar 25 '14 at 12:06
  • Do you mean if there is any performance boost when you swap high res Textures with low res textures, if you zoom out? Well i don't really think that it will speed it up. It would be better to set the manification and minification filters, that fit the best. Look at this: http://www.badlogicgames.com/wordpress/?p=1403 – Robert P Mar 25 '14 at 13:23

0 Answers0