androidlibgdxasset-management

Reloading Assets after android app has been paused


According to this libgdx wiki page https://github.com/libgdx/libgdx/wiki/Managing-your-assets OpenGL resources like Textures need to be reloaded after app has been paused.

Here is my way to manage libgdx app assets

I am loading all assets using assetManager during showing splashScreen using them whenever I need using assetManager.get()

Here is my code from the start:

public class GameMain extends Game {

    private AssetManager manager;

    @Override
    public void create() {
        manager = new AssetManager();
        setScreen(new splashScreen(this));
    }

    @Override
    public void render() {
        super.render();
    }

    @Override
    public void pause() {
        super.pause();
    }

    @Override
    public void resume() {
        super.resume();
    }

    @Override
    public void resize(int width, int height) {
        super.resize(width, height);
    }

    @Override
    public void dispose() {
        super.dispose();
        manager.dispose();
    }

    public AssetManager getAssetManager() {
        return manager;
    }
}

SplashScreen:

public class SplashScreen implements Screen {

    GameMain gameMain;

    public SplashScreen(GameMain gameMain) {
        this.gameMain = gameMain;
    }

    @Override
    public void show() {
        loadAssets();
    }

    public void loadAssets() {
        gameMain.getAssetManager().load("example.atlas", TextureAtlas.class);
        gameMain.getAssetManager().finishloading();
    }
}

My question: Should I call manager.update() in each Screen.resume() or not?


Solution

  • Your implementation is fine, you do not need to manager.update() unless you are loading your assets asyncly. In this case you already loaded assets. But always reach your assets using get parameter.

    If you dispose your texture onPause or onStop methods, you should reload them.