Game Loop: Difference between revisions

From C# Gamedev Wiki
No edit summary
No edit summary
Line 2: Line 2:


<syntaxhighlight lang="cs">
<syntaxhighlight lang="cs">
public void GameLoop()
void GameLoop()
{
{
     while (true)
     while (true)

Revision as of 13:59, 9 June 2024

A game loop is a continuous loop that runs an Update() method and a Draw() method. Below is the simplest example of a game loop:

void GameLoop()
{
    while (true)
    {
        Update();
        Draw();
    }
}

In practice game loops may have a lot more code. They may wait a certain amount of time between passes, do less processing on certain passes than others, contain exit logic, etc.

There are two main types of game loops:

  • Fixed Step - the loop processes equal intervals of game time
  • Variable Step - the loop processes varying intervals of game time