1
votes

i am storing textures for my game in a static class. They are loaded from a manager and into a static array in this class.

each screen has a dispose method but where should i call dispose on the textures. does libGDX only dispose on application exit and thus I should dispose the textures in every screen?

1

1 Answers

5
votes

It is a bad idea to hold all your texture is static array in static class. It is very hard to manage memory and control which texture will be removed by GC when you minimize your game or in other similar cases.

I recommend you to use AssetManager for loading and disposing your resources. You can find lots of useful information about AssetManager and resources management here Managing your assets

About your second question: I don't recommend you to dispose/load all textures when you change screens. I use next approach:

  1. On the game start show loading screen and load all often usable textures (like buttons, main menu graphic, main character, dialogs etc) with AssetManager. If your game is small you can load all game textures here.
  2. Don't dispose this textures until game closing.
  3. When you change screens try to load/dispose only dynamic textures (for example if every your level has different background, you can load/dispose this backgrounds).
  4. Always use Texture packer for your graphic.
  5. Use tinypng in order to compress your .png graphic.

P.S If you want to hold all your textures or any other assets in one class. Create Singltone class which will hold Map<String,Texture> where String is name of texture or full path.