2
\$\begingroup\$

I have a HexGame class extending Game and various Screens that receive the game object in their constructor. I was thinking of having one AssetManager in the game class and using it to load the necessary assets in each screen's constructor and unload them in the screen's dispose method. The alternative would be to use a new AssetManager in every screen. What would be best practice?

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

I would suggest using a single AssetManager, unless your assets are so large that memory would be a problem.

Again, depending on your size, you may also want to just load all assets up front. You would probably prefer to not load and unload assets during game play if it can be avoided. This will make screen transitions quicker/smoother.

One reason though to use multiple AssetManagers is if you're loading from different locations. As an example, for my last LibGDX project, I was loading a small number of included assets locally, but also loading assets from AWS S3, with some local caching. So I had two AssetManagers to handle those cases.

\$\endgroup\$
  • \$\begingroup\$ Assuming I use a single manager and an asset in a screen is never going to be used again in another screen, isn't it wise to unload it upon screen disposal? \$\endgroup\$ – alfoks Jul 31 '17 at 21:39
  • 1
    \$\begingroup\$ @alfoks possibly if you really need to conserve space. But that sounds like premature optimization. Also is it really only going to be once? I'd be more concerned that the design plans to build something that's only used once. Effort vs. reward seems low. \$\endgroup\$ – Chris Aug 1 '17 at 2:57
  • \$\begingroup\$ Talking theoritically. I'm still building the skeleton of a game with hex maps. I have 2 - 3 ideas of what game to build from that. But yes it makes sense. Logically a game will have 3 - 4 screens. \$\endgroup\$ – alfoks Aug 1 '17 at 11:42

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.