Game Development Reference
In-Depth Information
{
}
}
In C#, functions can be stored as variables by using a delegate that defines the
function signature—what the function returns and what parameters it takes in.
In this case, a delegate is used to define a function type with no return value or
parameters; it's named LoopCallback . FastLoop has one constructor that
takes in the callback. The callback will be called every frame to allow the game to
update itself.
All C# form programs have a static class called Application . This class re-
presents the program and its settings. It can also be used to modify a program so
that it can be used in real-time.
A program can have a large number of events to handle; the user might be
maximizing the form or Windows may be shutting down. The Application is
the part of the code that handles all these events. When it has no events to handle,
it calls a callback Application.Idle . This means it's about to enter idle time.
This idle time, when the application is not busy, is when the game logic needs to
be updated. To use the Application code, using System.Windows.
Forms needs to be added near the top of the file.
using System.Windows.Forms;
namespace GameLoop
{
public class FastLoop
{
public delegate void LoopCallback();
LoopCallback _callback;
public FastLoop(LoopCallback callback)
{
_callback ¼ callback;
Application.Idle += new EventHandler(OnApplicationEnterIdle);
}
void OnApplicationEnterIdle(object sender, EventArgs e)
{
}
}
}
 
Search WWH ::




Custom Search