Android Question LibGDX Question - Reloading Assets

Discussion in 'Android Questions' started by wonder, Sep 12, 2015.

  1. wonder

    wonder Expert Licensed 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: Sep 12, 2015
  2. Informatix

    Informatix Expert Licensed 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.
     
    wonder likes this.
  3. wonder

    wonder Expert Licensed 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: Sep 12, 2015
  4. Informatix

    Informatix Expert Licensed User

    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.
     
    wonder likes this.
  5. wonder

    wonder Expert Licensed 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?[​IMG]
     
  6. Informatix

    Informatix Expert Licensed User

    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
     
    wonder likes this.
  7. wonder

    wonder Expert Licensed 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. :)
     
  8. Informatix

    Informatix Expert Licensed User

    I don't understand what you mean by loop. It's just the sequence of events when the application is resumed.
     
  9. wonder

    wonder Expert Licensed User

    Sorry, I wasn't thinking clearly enough. Everything is perfectly clear in your tutorial.
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice