Game Development Reference
In-Depth Information
Back to our member variables, the second one is a
Factory
object that we will be
using to set up our Direct2D stuff. It is used to create Direct2D resources such as
RenderTargets
. The third variable is a
PathGeometry
object that will hold the
geometry for the first thing we will draw, which will be a rectangle. The last three vari-
ables are all
SolidColorBrush
objects. We use these to specify the color we want
to draw something with. There is a little more to them than that, but that's all we need
right now.
The constructor
Let's turn our attention now to the constructor of our Direct2D game window class. It
will do two things. Firstly, it will call the base class constructor (remember the base
class is the original
GameWindow
class), and it will then get our Direct2D stuff initial-
ized. The following is the initial code for our constructor:
public GameWindow2D(string title, int width,
int height,bool fullscreen)
: base(title, width, height, fullscreen)
{
m_Factory = new Factory();
WindowRenderTargetProperties properties =
new WindowRenderTargetProperties();
properties.Handle = FormObject.Handle;
properties.PixelSize = new Size(width,
height);
m_RenderTarget = new
WindowRenderTarget(m_Factory, properties);
}
In the preceding code, the line starting with a colon is calling the constructor of the
base class for us. This ensures that everything inherited from the base class is initial-
ized. In the body of the constructor, the first line creates a new
Factory
object and
stores it in our
m_Factory
member variable. Next, we create a
WindowRender-
TargetProperties
object and store the handle of our
RenderForm
object in it.
Note that
FormObject
is one of the properties defined in our
GameWindow
base