Game Development Reference
In-Depth Information
not written by us, but we can still use it because we have indicated in the beginning
of our program that we need things from the library
Microsoft.Xna.Framework.Graphics
.
So, a compilation unit consists of a number of
using
instructions followed by a
number of top level declarations. We can again use a syntax diagram to describe
this:
3.3.9 Subclasses: A Special Version of Another Class
Let us look at the class header again:
class
BasicGame : Game
Game
is in fact also a class, and it comes from the library
Microsoft.Xna.Framework
,
hence the need for the
using
statement in the first line of the program. So why is it
placed after the
BasicGame
class name? Although for now it is not yet so important
to know what it means exactly, you can read this as: '
BasicGame
is a special version
of
Game
'.
Game
is a class, so it contains a group of methods as well.
BasicGame
is a
special version
of the
Game
class, so it
inherits
all of the methods that were in the
Game
class. We can then add our own methods to this class, or rewrite some of the
methods that were in the original
Game
class, such as the
Update
method or the
Draw
method. If this seems a lot to take in, do not worry about it, we will discuss this in
much more detail later on.
3.3.10 Calling a Method
When the instruction
GraphicsDevice.Clear(Color.Olive);
is executed, we can also say
that we
call
the
Clear
method. In other words: we want the program to execute the
instructions grouped in the method
Clear
. This group of instructions does exactly
what we need for this example, namely clearing the screen and setting a background
color. However, we need to give some extra information to this method, because it
needs to know
which
color to set the background to. This extra information is also