Game Loop: Difference between revisions

From C# Gamedev Wiki
(Created page with "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 processe...")
 
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:


public void GameLoop
<pre>public void GameLoop
{
{
     while (true)
     while (true)
Line 8: Line 8:
         Draw();
         Draw();
     }
     }
}
}</pre>


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.
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:
There are two main types of game loops:
 
*[[Fixed Step]] - the loop processes equal intervals of game time
[[Fixed Step]] - the loop processes equal intervals of game time
*[[Variable Step]] - the loop processes varying intervals of game time
[[Variable Step]] - the loop processes varying intervals of game time


[[Category:Basics]]
[[Category:Basics]]

Revision as of 10:36, 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