Game Loop

From C# Gamedev Wiki
Revision as of 10:36, 9 June 2024 by Winkio (talk | contribs)

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:

public 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