Game Development Reference
In-Depth Information
// Tell the render target that we are done
drawing.
m_RenderTarget.EndDraw();
}
With that, our rendering code is now complete. The
if
statement at the top prevents
the program from crashing when it is first starting up or shutting down. The next
two lines tell the render target we are ready to begin drawing by calling the
Be-
ginDraw()
method, and then clear the screen by calling the
Clear()
method. The
next line calls our
RenderWorld()
method to draw the game world. But then, the
call to the
RenderDebug()
method is preceded by
#if DEBUG
and followed by
#endif
. These are known as
preprocessor directives
. This one checks if a sym-
bol named
DEBUG
is defined, and if so, the code inside this
if
directive will be com-
piled into the program. Preprocessor directives are processed by the
preprocessor,
which runs before the compiler when you compile your code. After the preprocessor
has finished its job, the compiler will run. There are a bunch of other preprocessor
directives besides
#if
, but they are beyond the scope of this text. When you com-
pile your code under the
Debug
configuration, the
DEBUG
symbol is automatically
defined for us, meaning our call to
RenderDebug()
will be compiled into the game.
In Visual Studio, you can change the compile configuration using the drop-down list
box that is just to the right of the
Start
button, which you click on to compile and run
your program. Visual Studio provides
Debug
and
Release
configurations. You can
also run a program by pressing the
F5
key.
The next line calls our
RenderPlayer()
method to draw the player character using
the appropriate animation frame from the robot's sprite sheet. And lastly, we call the
EndDraw()
method to tell the render target that we are done rendering this frame.
Handling user input
Now, we need to add some code into our
UpdateScene()
method to handle player
input:
base.UpdateScene(frameTime);
// Figure out which grid square each corner of