Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm making a 2D XNA game. I'd like to implement loading screens when stuff has to load for a while. Like when I login to an account, connect to the server, and generate worlds. I'm pretty sure it needs to be multithreaded, because I want to be able to do something like "Generating World 10%...11%...".

       //Call StartLoading("Generating World"); or something
       //Starter generating, Updating progress...
       //End loading screen and fade into world

Help appreciated, I'm new.

share|improve this question
Eek. What have you tried already? This site isn't really for "Write my code for me" type situations. – Byte56 Mar 29 '12 at 20:25
Im not trying to ask for exact code, Id just like a method too do it, I know how multithreading works, But havent tried it with XNA and am a little unsure what approach to take on how to make the other thread draw the loading screen while something else is loading. – Cyral Mar 29 '12 at 20:28
I see, well the way your question is laid out, it looks like "Fill this function for me". I recommend you research it and try on your own first, then ask specific questions if you have them. I'm sure there are plenty of pages out there for loading screens in XNA. – Byte56 Mar 29 '12 at 20:35
Welcome to! – ashes999 Mar 29 '12 at 21:10
up vote 1 down vote accepted

You don't need multi-threading at all, but some knowledge in parallel programming could be useful.

Do your load in batches in your game loop and you'll be fine.

share|improve this answer

I'd highly recommend looking at the following guide:

I had a look at it yesterday, and pulled out the loading screen code for a project I was working on, think it might be of help to you.

share|improve this answer

I wouldn't really call multithreading overkill. It at least doesn't lock up the game/system. So what I would do is have a counter for percentage, load everything in a thread, and for each item loaded increase the counter (by 1/number of items for 0-1 scale). Then, in the draw function, just have something draw current percentage. Then, once the data is finished loading, set a flag to true saying that the game has been loaded (this is important so that you do not crash the game because it wants to draw what hasn't yet been loaded).

share|improve this answer

Disclaimer: This is kinda off-the-cuff advice, so take it as such.

If you're trying to multi-thread, it might be overkill for a loading screen. Unless you have a cool loading screen like (I think Fallout's) install screen, where you play Arkanoid while it installs!

You can usually do this with something simple, like using a timer on a short (1 second?) interval to update the "loaded" percentage, while your main application loads what you need.

Plus, if your game is small enough, you won't even need a loading screen!

share|improve this answer
A timer sounds lik it might work, If I called Draw() during it. While I was offline I think i thought of a soulution, Ill post it when Im done coding it. – Cyral Mar 29 '12 at 21:35
One thing Im stuck on, actually drawing it, I set up a draw method for it, but when I call it from my Logon method it dosent do anything. – Cyral Mar 29 '12 at 22:03
I don't know what you mean. Just have a timer that checks how much is loaded and updates some integar value to be the percentage. Draw just uses that to draw the progress bar. – ashes999 Mar 30 '12 at 0:58
I don't know if I got you right, but if you're trying to draw something inside the Load or Update functions, you're not doing a good thing. – Gustavo Maciel Mar 30 '12 at 2:37
Im trying to draw loading screens when I login, Generate a world etc. My problem is drawing the screen while its loading. I already got the class set up but cant seem to draw it. – Cyral Mar 30 '12 at 21:29

I've done something like this:

  • A class ContentLoaderSpool that have:

    . One Dictionary keyed by the paths of the files to load, with the value as the instance of the content loaded (Texture2D, Song, Video and so);

    . One property to flag if there's some content still need to load;

    . A method asking for start loading the content. It iterates through the Dictionary and populates their values. This method works in a parallel thread with high priority. While this method is running, the main game loop continues normally.

The game loop can grab informations of the Spool, to update one progress bar or see if the entire collection of content were loaded and finally change to the next screen.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.