Game Loop: Difference between revisions
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> | ||
public void GameLoop | |||
{ | { | ||
while (true) | while (true) | ||
| Line 8: | Line 9: | ||
Draw(); | Draw(); | ||
} | } | ||
}</ | } | ||
</syntaxhighlight> | |||
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. | ||
Revision as of 12:45, 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