Game Development Reference
In-Depth Information
use to build the geometry of our rectangle. The
using
block will automatically dis-
pose of the
GeometrySink
object for us when program execution reaches the end
of the
using
block.
Note
The
using
blocks only work with objects that implement the
IDisposable
in-
terface.
The next four lines calculate where each edge of our rectangle will be. For example,
the first line calculates the vertical position of the top edge of the rectangle. In this
case, we are making the rectangle's top edge be 25 percent of the way down from
the top of the screen. Then, we do the same thing for the other three sides of our
rectangle. The second group of four lines of code creates four
Point
objects and ini-
tializes them using the values we just calculated. These four
Point
objects repres-
ent the corners of our rectangle. A point is also often referred to as a
vertex
. When
we have more than one vertex, we call them
vertices
(pronounced as
vert-is-ces
).
The final group of code has six lines. They use the
GeometrySink
and the
Point
objects we just created to set up the geometry of our rectangle inside the
PathGeo-
metry
object. The first line uses the
BeginFigure()
method to begin the creation
of a new geometric figure. The next three lines each add one more line segment to
the figure by adding another point or vertex to it. With all four vertices added, we then
call the
EndFigure()
method to specify that we are done adding vertices. The last
line calls the
Close()
method to specify that we are finished adding geometric fig-
ures, since we can have more than one if we want. In this case, we are only adding
one geometric figure, our rectangle.
Drawing our rectangle
Since our rectangle never changes, we don't need to add any code to our
UpdateS-
cene()
method. We will override the base class's
UpdateScene()
method any-
way, in case we need to add some code in here later, which is given as follows: