Game Development Reference
In-Depth Information
The GameWindow class
The GameWindow class will provide basic game window functionality. It will provide
all of the basic properties we want to have in our game window, and it will be used
as a base class. We will not be making many game window subclasses in this topic,
but the idea here is that you can make different subclasses for different types of game
windows. For example, you can have a game window class for DirectX 10 as well as
a game window class for DirectX 11.
The main things we need to implement for the GameWindow class are a constructor
to initialize it, Game Loop , UpdateScene() and RenderScene() methods, and
a cleanup code for when the window is closed. A game loop is a method that is es-
sentially the heart of a game engine. It is called repeatedly as long as the game is
running. It is called once per frame in order to run the code that makes everything
happen in our game world. It calls the UpdateScene() method, which updates ob-
jects in our game world. For example, this method will call on the physics system to
simulate the physics for objects that are moving around in our game world.
Once UpdateScene() has finished updating the states of all of the objects in our
game world, the game loop will then call the RenderScene() method to draw the
current frame. So ultimately, the game loop simulates and draws the game world
frame-by-frame. Each time it is called, it simulates another frame.
A video game is composed of frames, just like movies are, except that in a video
game each frame is being generated on the fly by the computer. Ideally, we want a
game to run at least at 30 FPS (frames per second) so that the video is smooth. If the
frame rate is too low, the game's video will become choppy, or worse the game can
become unplayable. Let's go ahead and get started with implementing our GameWin-
dow class. First, we need to add some using statements at the beginning of the
GameWindow.cs file so that we can use some classes defined by SlimDX and the
.NET Framework:
using System;
using System.Windows.Forms;
using System.Diagnostics;
using SlimDX;
using SlimDX.Windows;
Search WWH ::




Custom Search