Game Development Reference
In-Depth Information
called BasicGame (lines 15-19). The following instruction initializes the graphics
device:
graphics = new GraphicsDeviceManager( this );
We are going to look into what this means exactly later on. In the Draw method,
we can now use the graphics device to clear the screen and to set it to a particular
color:
GraphicsDevice.Clear(Color.Olive);
Clear is a method of the GraphicsDevice class. In order to execute this method,
we have to write in front of it what it belongs to. In this case, it is the graph-
ics device. The graphics device and the method that belongs to it are sepa-
rated by a dot. After the method name you see parentheses. We need to pro-
vide the values for the parameters that this method needs between these paren-
theses.
Let us look in a bit more detail at the parameter that we pass to this method. It
represents the color to paint the window after it has been cleared. For this, we use
another class, the Color class. This class is used to create different colors, such as
olive in our example, but there are many more available, as we have already seen in
the first chapter. You can even make your own color by combining red, green, and
blue values. As you can see, we did not write Color.Olive() with parentheses. This is
because Olive is not a method of the Color class, but it is called a property . There
are a few differences between properties and methods. One is that a property does
not take parameters, which is why we omit the parentheses. We will discuss what
properties are in more detail later on. For now, let us just say that these properties
give us information in the shape of a color. So Color.Olive results in information that
describes the color 'olive'. Because the expression Color.Olive is placed inside the
parentheses of the Clear method, this information is passed as a parameter to that
method. So now, the Clear method knows that it needs to set the background color
to olive and it can do its job.
Next to creating the graphics device, there is also another line of code in the
BasicGame method:
Content.RootDirectory = "Content";
This instruction indicates where our game program can find sounds, images or other
assets that are used in the game. At the right-hand side of the equals sign, you can
see the word 'Content' between double quotes. If something is written between
double quotes, the compiler interprets it as text . In this case, the text indicates the
folder in which the game assets are located. Because the BasicGame program does
not use any assets, we could also have left out this instruction from the program
and it would still work fine. Similarly, there are a few other instructions that we will
not deal with now, because they are related to loading and displaying game assets.
In the next chapter, we will show why these instructions are needed and what they
do.
 
Search WWH ::




Custom Search