Datasheet
The Game1 class contains the Initialize, Update, and Draw methods mentioned a little bit earlier.
Initialize does nothing for now and Update just checks if the Back button on the first connected
gamepad was pressed.
For now you are just interested in the
Draw method, which basically just executes the following line to
clear the background to a specific color:
graphics.GraphicsDevice.Clear(Color.CornflowerBlue);
F5 and Go
If you press F5, the project starts (same as Debug-Start Debugging) and you see the screen shown in
Figure 1-11, which shows the blue color on a blank boring window that is specified in the
Draw method.
To feel like you are actually doing something, change the
Color to Color.Green and press F5 again.
The window now has a green background. The
Clear method of the graphics device has other over-
loads that can be used to clear the depth and stencil buffers, which will be done automatically if you just
set the color. For example, later in this book you will just need to clear the depth buffer, but not the color
of the background. To do that you just write the following line:
graphics.GraphicsDevice.Clear(ClearOptions.DepthBuffer,
Color.Green, 1, 0);
By default, the ClearOptions are set to ClearOptions.Target | ClearOptions.DepthBuffer,
which means both the background color and the depth buffer are cleared. By the way, if you don’t know
it already, the | operator between the
ClearOptions flags will combine both settings.
Figure 1-11
16
Part I: XNA Framework Basics
61286c01.qxd:WroxPro 1/21/08 3:44 PM Page 16