Modifying Your Game

All right, enough talk. You're itching to get into game development and ready to put something cool into your game. Let's make it happen.

Take a look at your Draw method. Currently, the method contains the following code:

protected override void Draw(GameTime gameTime)
{
    GraphicsDevice.Clear(Color.CornflowerBlue);

    // TODO: Add your drawing code here

    base.Draw(gameTime);
}

The first thing to notice here is the parameter that your Draw method receives. The parameter is of the type GameTime and represents the time that has passed during the execution of your game. Why do you need a variable keeping track of time? Because computers do not all run at the same speed. This variable helps you determine when animations and other events should happen based on actual game time rather than processor speed. The gameTime variable will be used throughout this book to gauge things such as framerate, animations, sounds, and other effects. The same parameter is also passed into the Update method, because many of the functions that control those effects need to be performed in the Update method rather than the Draw method.

At the end of the method, you call the Game1 object's base Draw method, which is essential in order to get cascading calls to Draw methods in GameComponents and other objects. That might not make sense to you now, but be assured that you want the base.Draw call in the code and you should not remove it.

Finally, let's look at the call to Clear using the GraphicsDevice ...

Get Learning XNA 3.0 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.