Drawing to Screen While Loading

What is the best way to draw to the screen while loading and unloading content? I’d love to be able to do animated loading screens, but if that’s not possible I’ll settle for static loading screens. I’ve searched quite a bit and there’s doesn’t seem to be a great way to achieve this in MonoGame/XNA. Thanks in advance for any help!

Give this a try:

http://xbox.create.msdn.com/en-US/education/catalog/sample/game_state_management

An alternative is a render target in front of your game world…

You might try creating a special scene (or many) for the purposes of loading/unloading your content. I haven’t tried this, but maybe you can load/unload your content on a background thread and have your scene render your progress.

If loading/unloading on a background thread doesn’t work, you could always queue up a bunch of individual tasks, then every update process the top of the queue. This will let draws through still so you can show your progress. Once loading (or unloading) is complete, transition to whatever scene you like.

The typical way this is done is to load a small number of assets synchronously (these will be used to draw the loading screen), then start a task that loads the rest of the content. At the end of the task, set a flag to tell the game Update method that the content loading has finished. In the game Draw method, while the flag is not set, draw the loading screen using only the assets loaded synchronously beforehand.

1 Like

Right, so that’s basically what I am attempting to achieve. The asset(s) for the load screen are already loaded and I have a Loading game state. I’m just having issues finding an example of setting up either a Task or a Thread to perform the loading in. Right now I’m just doing it in the main (only) Thread and my Draw calls are not presenting to the screen. I assume the loading is locking it out. Any chance you have a small example of how to initialize a loading Task and execute it?

XNA Loading Screen
http://xboxforums.create.msdn.com/forums/t/45017.aspx

I managed to figure it out from the comments and various links you all used, so thanks for the help! I really was just having an issue with syntax. I needed to add “Object stateInfo” as a parameter to the method I was adding to the ThreadPool. So, for others who may have questions:

//Method that you want to call private void LoadAdditionalContent(Object stateInfo) { //do loading }

//Call to add method to ThreadPool
ThreadPool.QueueUserWorkItem(LoadAdditionalContent);

1 Like

Yeah, creating a thread is the simplest way to do the trick.
Now if you want make an animation you can do it for example by making a gif animation at first. Then make a screen capture video of the animation because of XNA 4.0 does not support gif format at all. The next thing to do is convert the video to correct wmv format which you can do using for example VideoPadVideoeditor by NCH Software. In my experience XNA does not complile any of online converted wmv videos.
Then back to our game:
When all the necceary variables are defined and the video has been load in to content at the top of content loading you can start your thread for example as follows.

1 Like

To start organising your project better so you don’t end up with a whole bunch of stuff in your main game class as per the comment above,

I like to have an abstract class called screen. There is always one active screen. The active screen is always updated and drawn in the main game loop.

Then you can create a loading screen. On the game starting the loading screen becomes the active screen.
The loading screen can then contain all the loading graphics and threaded loading code. When loading is done then you call for your active screen to change to a menu screen. You can contain all your menu graphics, ui and logic in this class.

Can then also have game screen, settings screen, start splash screens etc.

It gets away from having all these different game states of what part of the game or ui should be shown.

You are absolutely right, but I was thinking about the laziest way :grin:
Here link to a simple samle of drawing video animation while loading content (XNA/Windows)