Game Development Reference
In-Depth Information
The next two lines create the RenderForm object, set its title text, and initialize it to
the size that was passed into the constructor. RenderForm is a SlimDX class that
represents a window for us to draw on. And finally, the last line simply subscribes the
GameWindow class to the Closed event of the RenderForm object. This causes the
GameWindow class to be notified when the window is closed.
Now that we have our constructor, we need to define an event handler for the event
we just subscribed the GameWindow class to. As you might guess, this event is fired
when the game window is closed (either by the user or programmatically). Here is
the code, which is pretty short as you can see:
public virtual void FormClosed(object o,
FormClosedEventArgs e)
{
if (!m_IsDisposed)
Dispose();
}
The if statement checks to see if the game window has already been disposed of.
If not, then it calls the Dispose() method to dispose of it.
The IDisposable interface
Currently, the declaration of our GameWindow class says that it does not inherit from
any other class, nor does it implement an interface. We are going to change this
because we are going to implement the IDisposable interface. It is a very small
interface so implementing it will be quick. First, we need to edit the declaration of our
class to say that it will be implementing this interface. To do this, simply go to the
beginning of the GameWindow class and change public class GameWindow to
public class GameWindow : IDisposable .
This tells the compiler that this class implements the IDisposable interface. Now
we have to adhere to this interface. It has one method that we need to implement.
This method will perform cleanup operations when the game window is closed.
There isn't much in this function at the moment, but here it is:
Search WWH ::




Custom Search