Game Development Reference
In-Depth Information
The
GameLoop
function should be called each frame. To do this, a new class
needs to be created. Right-click the
GameLoop
project in the solution explorer
tab and choose Add > Class. This will prompt you for a class name; name the
class
FastLoop
. The
FastLoop
class is going to be used by the
Program
class.
It will force the function
GameLoop
to be called each frame. Before
GameLoop
is written, let's consider how it might be used.
static class Program
{
static FastLoop _fastLoop
ΒΌ
new FastLoop(GameLoop);
///
<
summary
>
/// The main entry point for the application.
///
<
/summary
>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
static void GameLoop()
{
// GameCode goes here
// GetInput
// Process
// Render
}
}
The
FastLoop
class will take only one argument. That argument will be the
function
GameLoop
. That's all that will be needed to convert a project so that it
continually executes.
Open FastLoop.cs. In the
Program
class, the
FastLoop
constructor call takes
in a reference to the function
GameLoop
. Therefore the
FastLoop
class must
define its constructor to have a function passed into it as a parameter.
public class FastLoop
{
public delegate void LoopCallback();
public FastLoop(LoopCallback callback)
Search WWH ::
Custom Search