Game Development Reference
In-Depth Information
GetElapsedTime should be called once per frame and this will keep track of
the time. The elapsed time is so important that it should be incorporated into the
game loop. Open the Program.cs file and change the game loop so it takes one
argument.
static void GameLoop(double elapsedTime)
{
// GameCode goes here
// GetInput
// Process
// Render
System.Console.WriteLine("loop");
}
FastLoop.cs needs to be changed as well; the delegate must take an elapsed time
value and the PreciseTimer needs to be added as a member.
public class FastLoop
{
PreciseTimer _timer ¼ new PreciseTimer();
public delegate void LoopCallback(double elapsedTime);
The timer is then called once per frame and elapsed time is passed on to
FastLoop 's callback.
void OnApplicationEnterIdle(object sender, EventArgs e)
{
while (IsAppStillIdle())
{
_callback(_timer.GetElapsedTime());
}
}
The game loop can now be used to smoothly animate any game! By the end of
this chapter, the game loop will be used to smoothly rotate a 3D triangle—the
''Hello World'' application of OpenGL programming.
Graphics
Now that the game loop is working, the next step is to get something to display on
screen. You can either continue the current project with FastLoop.cs and Game-
Loop.cs or you can make a new project and modify it so it has a fast game loop.
 
 
Search WWH ::




Custom Search