Loading, Screens, and General Trickery

Assume that you are using the “scene” paradigm.

Lets say you want to load in a new scene.

Here are the steps

  1. Disable controls
  2. Fade the loading screen in
  3. Read the scene from a file
  4. Set the new scene
  5. Fade the loading screen out
  6. Re-enable controls

Here are some problems to consider:

  1. Fading in and Fading out take time. How would you follow up on something that finishes in the future, specifically on another cycle of the game loop.

  2. Since loading screens usually has some type of animation, you probably do not want to read the scene on the game loop thread. How would you execute it on another thread.

  3. What class do you place the code for #1 and #2 in?

  4. How do you test your approach?

I have already solved this for my own project. But I am curious into what others will say. Also, this took me 2 hours on thinking for organize thread execution. I hope no one else suffers from this problem.

I don’t really have much to say from my own experience on this topic, but take a look at libGDX’s approach in their scene2d scene graph. Specifically the SequenceAction.

Maybe you already came by it while googling, but a short search gave me this which looks pretty promising: https://stackoverflow.com/questions/12016675/how-to-create-loading-screen-in-libgdx