简体   繁体   中英

Proper use of the AssetManager class in libgdx

I am developing a platform game in libgdx in which has few levels and a player that running on the ground, very simple name.

I just started to use the AssetManager class and I have a question:

1) Am I need to load all the tmx maps and all the atlasses at the beginning of the game (before the menu, for example). Or I need to show before each level the loading screen ang load all the staff their?

2) The user can return to the menu screen at every time he want, so am I load the menu staff before the menu and only unloading them when the user quit the game?

Thank for those who will help me, and sorry for my poor english.

It depends on how heavy your assets are.

AssetManager is a versatile class and allows you to perform loading in any order at any time. All use cases stated by you are possible to achieve using AssetManager .


  1. You can load all tmx maps and all atlasses at the beginning of the game.
    You can also load them level wise.

    Now the question is what you should do.

    • First case is easy to implement. Less screen changing. More initial loading time (but never again). Possibility of memory overflow.
    • Second case is considered ideal. Less loading time initially, but have to do it every time (which is also low btw). Memory efficient. Have to switch to loading screen each time.

  2. Same in case of menu too. You can do both. If the menu is lightweight, you should keep it loaded. It's a good idea to have menu ready each time (at least pause menu).
    Provide a loading screen for menu only if it is hard on memory.


Since you have so much freedom, you should take these decisions depending upon how would the user experience be in each case. Players don't like to be disturbed frequently by a loading screen. But it does not make sense to make him/her wait for loading levels they are not going to use.

Just make sure to have the asset loaded before using it. If loading code is becoming distributed, don't worry about redundant calls of load method. AssetManager loads each asset exactly once irrespective of how many times have you asted it to load a particular asset.

Good luck.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM