IsLoadingScreen

Introduction

The IsLoadingScreen property can be used to mark a Screen as a loading screen. Loading screens can be used when transitioning into a Screen which must load a lot of content or when returning back into the app after it goes to sleep (tombstones) on a phone.

Setting IsLoadingScreen

To mark a Screen as a loading screen, simply set the IsLoadingScreen property to “True”:

IsLoadingScreen.PNG

Using a loading screen

For this example we’ll assume you have a Screen called LoadingScreen which has its IsLoadingScreen property set to true. To use the LoadingScreen:

  1. Identify which screen transitions you want to use a LoadingScren between. For example, you may want to use the LoadingScreen between a main menu screen and the game screen if the game screen has a lot of content to load.
  2. Locate where you want the transition to occur (like when the user presses the Start button or clicks on a button) and add the following code:

Manually setting the next screen to load

You can manually set the next screen even if you do not have an instance of a LoadingScreen (which is required for the TransitionToScreen method. You can do this by setting the static NextScreen property. This is useful if:

  1. You are using the loading screen as the first screen in your game
  2. You are using the loading screen to display something while your app returns from tombstoning
  3. You want to set the next screen before you have created the loading screen (such as in response to a button push)

The following code shows how to use the LoadingScreen as your first screen. This code belongs in Game1.cs’s Initialize method. Note that ScreenManager.Start will automatically get generated by Glue, so you would only add the code to set the LoadingScreen’s NextScreen.

What does TransitionToScreen do?

The TransitionToScreen method is an easy way to move between two Screens. It will

  1. Unload/destroy the current Screen
  2. Load the LoadingScreen and make it the primary Screen
  3. Begin loading the argument Screen (GameScreen in the example above) in a secondary thread
  4. Performs every-frame activity on the LoadingScreen which can be used to play animations or other activity to give the user an indication that the game is not frozen.

Tips for using loading screens

The IsLoadingScreen property can help you create loading screens quickly; however there are some things to consider which can make the user experience better:

  • Keep the logic in the loading screens simple to reduce the amount of resources spent on running your loading screen.
  • Keep the amount of content loaded on your Screen low. If this is not possible or desirable, consider making the content that is part of your loading screen also a part of Global Content Files. Your game will pre-load this content if you are using async global content loading.
  • Consider making your loading screens use a global content manager. This means the loading screen’s content (such as used textures and Scenes) will always remain in memory making transitioning to a loading screen very fast.
  • Be careful using minigames in your loading screen. There is currently a patent held by Namco on the use of minigames in loading screens.