Info – How The XNA Framework Operates – Beginners

Unlike Windows programs (which are event driven), XNA programs runs in a continuous loop until the game exits. While the game is running, the Garbage Collector releases/reclaims managed referenced memory which isnt used. On a normal Windows PC, there are 3 Generations of memory, but because the Xbox 360 uses the .NET Compact Framework assembilies, there is only 1 Generation. This can cause Latency within your programs if you are not careful with memory and the GC needs to run often.

As i said previously, the main application calls your game (inherited by Microsoft.Xna.Framework.Game). The Game class contains various methods which are called during runtime in the following order:

  1. Main games Initialize method.
  2. Each game component Initialize methods (if you have any)
  3. If your game has any Drawable game components, then their LoadContent methods are called.
  4. Main games LoadContent methods are called.
  5. Main games Update methods are called.
  6. Each game components Update Methods.
  7. Main games Draw methods are called.
  8. Each game drawable components Draw methods are called.
  9. The game then loops around 5-8 (ie Update then Draw methods for the main game and components)
  10. If you reset the device, then UnloadContent is called.

This is a basic illustration of what goes on within the nuts and bolts of the loop. The XNA Framework handles the Game Loop within the Framework, either by a fixed or variable step timing. The default is fixed step and it targets 60 FPS (1/60th second).
What this means is that Update method is only called when the Game member TargetElapsedTime elapsed. If it is not time to call Update again, the Draw is called. Microsoft have also built an IsRunningSlowly, which means the game is running under 60 FPS, so XNA tries to compensate and calls Update extra time until caught up (without calling Draw in between).

For more information on the Application Model Overview – See here.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: