Game Loop: Difference between revisions

From C# Gamedev Wiki
No edit summary
No edit summary
Line 1: Line 1:
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:
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:


<syntaxhighlight lang="C#" line>
<syntaxhighlight lang="cs" line>
public void GameLoop()
public void GameLoop()
{
{

Revision as of 13:32, 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:

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