About the Game Loop
Learn all about the game loop and how it is used to create games using SwinGame.
The Game Loop
Most games perform a game loop, this is a loop that repeats until the user quits. It performs three basic tasks: handle input, update game, and draw game. The basic structure of the loop is shown below in pseudo code:
repeat call HandleInput call UpdateGame call DrawGameOnScreen until WindowCloseRequested
Handle input is where you get all the user input events and process them, this includes performing tasks like moving the user character based on keyboard input. Before you get started on working with input you should read About Input.
The update game section of the game loop is where you update the world based on what just happened during the handle input phase. For example you might want to move a ball, this is done in the update game section.
Once you've updated the game you now need to draw the updated game to the screen so that the user can see it, this is done during this phase. In this section you should clear the screen and re-draw all of your characters and images back onto the screen. If you have not already, you should check out About Graphics, and About Images for information about drawing in SwinGame.