0
votes

I started developing a game using libgdx. Now i want to start managing all my assts. I looked at this, but it is not really what i need. I want to be able to load the textures on screen change (GameScreen: load game assets, MenuScreen: dispose game assets, load menu assets.) and then get access everywhere. This is why i thought about a singleton. I am using scene2d and subclasses of image as my ingame characters. The constructor takes a drawable so i need to access it in my stage subclass, where i create all my characters. I also need access to the assets in my actors, cause if they shoot i want to play the shoot sound. For this i would like the MyAssetManager to load and apply the sound preferences (Volume...), which are stored with the libgdx Preferences. How can i realize that? Is a singleton a good idea? Should my asset manager use the libgdx assetmanager internal?

EDIT: I think about having an AssetManager, to load the ressources and a SoundManager to play the sounds. I will load the preferences (sound volume) on startup and keep them as variables. The textures are given to the actors in the constructor. What to you think about that?

1

1 Answers

2
votes

How can i realize that? Is a singleton a good idea? Should my asset manager use the libgdx assetmanager internal?

Why not both? Using the AssetManager has many advantages:

  • Loading of most resources is done asynchronously, so you can display a reactive loading screen while things load
  • Assets are reference counted. If two assets A and B both depend on another asset C, C won't be disposed until A, B and C have been disposed. This also means that if you load an asset multiple times, it will actually be shared and only take up memory once!
  • A single place to store all your assets.
  • Allows to transparently implement things like caches (see FileHandleResolver below)

So, what about you make a Singleton class, that uses AssetManager to load/unload your assets.

(By the way, The old wiki on google code you link won't be updated anymore, Actually it is just matter of time before its deleted. Link to the new wiki instead: Managing your Assets)