Android Question LibGDX Question - Reloading Assets

wonder

Expert
Licensed User
Longtime User
Let's say the player has reached the end of the first level.
What's the proper way to (re)load everything for Level 2?

Basically, how to destroy all Level 1 assets and load all Level 2 assets:
- Background Textures
- Character Textures
- Sounds
- Fonts

EDIT: After reading the tutorial once again, I came across the Screen Manager (
lgScreenManager) section. Is this what I need? Am I on the right track?
 
Last edited:

Informatix

Expert
Licensed User
Longtime User
To manage the assets, the best is probably to have a lgAssetManager object dedicated to each level so you can dispose or load your assets with a minimal number of lines of code. The lgScreenManager and lgScreen objects will help you manage your different screens (splash screen, interstitial ad, main menu, options, levels, etc.). You can place the code of your asset managers in the Show and Hide events of your screens.
 
Upvote 0

wonder

Expert
Licensed User
Longtime User
Thank you for your reply, Fred! :)
I think I'm starting to understand...

A few questions...
1. If I go with the lgScreenManager solution, do I have to "transfer" all my current LG_Render code into the LGSx_Render sub?
2. If so, should I then leave the LG_Render empty as seen in your example?
3. I see in your example that you dispose the assets "manually" without have to use the lgAssetManager. Is this correct?
4. When a screen is hidden, if I don't dispose the assets, will it still run on the background, slowing down the game?
5. Every time I change the screen (ex: from 1 to 2), the Show even is raised, thus (re)loading all the current screen's (2) assets. Is this correct?
 
Last edited:
Upvote 0

Informatix

Expert
Licensed User
Longtime User
Thank you for your reply, Fred! :)
I think I'm starting to understand...

A few questions...
1. If I go with the lgScreenManager solution, do I have to "transfer" all my current LG_Render code into the LGSx_Render sub?
2. If so, should I then leave the LG_Render empty as seen in your example?
3. I see in your example that I dispose the assets "manually" without have to use the lgAssetManager. Is this correct?
4. When a screen is hidden, if I don't dispose the assets, will it still run on the background, slowing down the game?
5. Every time I change the screen, the Show even is raised, thus (re)loading all the current screen's assets. Is this correct?
1) Yes. But you may need the LG_Render event to load asynchronously the first assets of your game with lgAssetManager. In this case, CurrentScreen is not set until the assets are loaded. While loading asynchronously, typically a loading screen is rendered with a few assets loaded directly.
2) Yes. It won't be called if CurrentScreen is set in LG_Create.
3) It's a demo with only a few assets so I don't really need an asset manager. In a real project, an asset manager is of greater importance and should be always used. Loading/disposing manually all the assets is tedious and prone to errors.
4) If it is hidden, that means it stopped rendering and another screen is displayed. Events are not raised concurrently.
5) The Show event does not load anything. It's up to you to decide if it's the right place to load some assets.
 
Upvote 0

Informatix

Expert
Licensed User
Longtime User
I understand... Thank you once again!

I know that your time is valuable, but can I ask you if my annotations are correct on this chart? Does this illustrate the a screen life-cycle?
screen_life_cycle.png
A few things are wrong or incomplete.
If you look at the log when you run the MultiScreen demo, you can see the order of events (LG is for the libGdx view events, S1 is for the screen events):
  1. LG_Create (CurrentScreen is set to S1 here)
  2. S1_Show
  3. S1_Resize
  4. S1_Render
Then, if the application is paused:
  1. S_Pause
When it regains focus:
  1. S1_Resize
  2. S1_Resume
  3. S1_Render
If another screen (S2) is set as the current screen:
  1. S1_Hide
  2. S2_Show
  3. S2_Resize
  4. S2_Render
If the application is closed:
  1. S2_Pause
  2. S2_Hide
  3. LG_Dispose
 
Upvote 0

wonder

Expert
Licensed User
Longtime User
So, one could say that the lgScreen "loop" consists of Resize, Resume and Render.
If I understood everything correctly, I believe am I now prepared to redesign / restructure the game in this sense.

As always, thank you for your help, I couldn't have achieved everything I achieved so far without it. :)
 
Upvote 0

wonder

Expert
Licensed User
Longtime User
Sorry, I wasn't thinking clearly enough. Everything is perfectly clear in your tutorial.
Informatix said:
The screens have the same life-cycle as the library, and thus the same events except that Create is named Show and Dispose is named Hide.
 
Upvote 0
Top