2
\$\begingroup\$

I am working on a LibGDX game and I would like to find out the best way to manage assets. Should I have one AssetManager that is passed through to my GameState init() method to load from each level, then unload all of those resources in the dispose() method of the gamestate.

Or, should I have a separate AssetManager in each gamestate which is passed to each of the entities and components within the gamestate and clear + dispose the entire AssetManager in the dispose() method of the gamestate.

\$\endgroup\$
0
\$\begingroup\$

No, you don't have to keep seperate assetmanager for different game states . One Assetmanager is enough for all the states. Moreover adding multiple Assetmanager leads to increase the load of GPU. Which will effect your Game play. So better use only one Assetmanager to load the all Assets. And Assetmanager is one of the class which should be disposed manually .So try to implement the below classes .

    public class Assets implements Disposable, AssetErrorListener {
     } 

So after implementing the Disposable interface you can access a "dispose" method (note:- only use,if ur making seperate class for dealing with the Assets). in that dispose method you can also write

 @Override
public void dispose() {
 assetManager.dispose();


}

So I'm prefering you to use only one assetmanager. and the above code is used to dispose the Assetmanager

\$\endgroup\$
1
\$\begingroup\$

Creating only one is probably better. If you have one object storing and managing the lifetime of assets that you share between all levels, that makes it trivial to share assets across each level (for example, common, always-loaded assets).

If you have one asset storage object per level, that does not naturally lend itself to sharing common assets (you could still make it work, depending on how complicated you wanted to make your asset management interface, but it comes almost for-free when you simply create one at startup and pass references to it to all your levels).

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.