Game Development Reference
In-Depth Information
using
Microsoft.Xna.Framework;
1
using
Microsoft.Xna.Framework.Graphics;
2
3
4
class
DiscoWorld : Game
{
5
GraphicsDeviceManager graphics;
6
SpriteBatch spriteBatch;
7
Color background;
8
9
10
static void
Main()
{
11
DiscoWorld game =
new
DiscoWorld();
12
game.Run();
13
}
14
15
16
public
DiscoWorld()
{
17
Content.RootDirectory = "Content";
18
graphics =
new
GraphicsDeviceManager(
this
);
19
}
20
21
22
protected override void
LoadContent()
{
23
spriteBatch =
new
SpriteBatch(GraphicsDevice);
24
}
25
26
27
protected override void
Update(GameTime gameTime)
{
28
int
red = gameTime.TotalGameTime.Milliseconds;
29
background =
new
Color(red, 0, 0);
30
}
31
32
33
protected override void
Draw(GameTime gameTime)
{
34
GraphicsDevice.Clear(background);
35
}
36
}
37
Listing 4.1
A program that displays a changing background color
you can see in Listing
4.1
,the
Draw
method has a parameter of type
GameTime
, and
the name of this parameter is
gameTime
. Inside the method, we can use the param-
eter just like we use a variable. So, when we are executing instructions inside the
Draw
method, the current game time is stored somewhere in the memory, and we can
access it with the name
gameTime
. The type of this parameter is
GameTime
, which is
a much more complicated type than an integer. In fact, the
GameTime
type consists