LoadingScreenState Basic Help

Jun 22, 2010 at 7:18 PM
I'm new to Nuclex but I have been thinking about using it for a long time now however. I am using the GameStateManager but need to figure out how to load content cleanly in a modular fashion from within my States. As a basic example: I have a background state which inherits from the base State class. I need to load just a single image but what is the best way to achieve this? I looked at the LoadingGameState class but was unsure of how to best go about using it as it seems low on documentation. Any help as to how to achieve a simple way to load content from within states and/or how to correctly and cleanly use LoadingGameState. Thanks for the brilliant library btw
Coordinator
Jul 2, 2010 at 7:58 AM
Edited Jul 2, 2010 at 8:00 AM

Sorry for the late reply!

You don't have to do the loading screen this way, but here's how the LoadingGameState is intended to be used:

Let's assume you just wrote a MissionGameState that runs the gameplay for a single level. You notice that this game state is loading so many resources that it takes several seconds to complete, so you decide to add a loading screen. So you...

  1. Implement the ILoadableGameState in the MissionGameState
  2. Write some code to asynchronously load your content and wire it up to the BeginLoad() and EndLoad() methods. This follows the standard .NET Asynchronous Method Pattern
  3. Derive another game state (one that shows a 'loading' screen) from LoadingGameState, let's call it MissionLoadingGameState
  4. Write some code to display an animated loading screen, progress bar or whatever in MissionLoadingGameState

Now, whenever you start a mission, instead of directly switching to the MissionGameState, switch to the MissionLoadingGameState and your loading screen will be displayed as long as the MissionGameState takes to load its content. Once it is done, the MissionLoadingGameState will automatically switch to the MissionGameState.