The Game Loop
The Game Loop is the central aspect behind each Video Game, and here is what it looks like:
- Update, Draw, Update, Draw, Update, Draw, ...
Let's find out what each one does and how often it happens...
Start happens one time at the beginning. The Start method is commonly used to load 3D models and textures, to initialize variables or sometimes to create the Game Window.
Update and Draw
As long as we are playing the game, Update and Draw will be called over and over again.
Update is used for all kinds of calculations, for example how the Hero's position changes while running, or how much Health an Enemy loses after hitting it.
Draw is used for all kinds of visual things, everything that we actually see. In here we don't calculate much at all, but instead we throw everything onto our Screen that we calculated before. If the Hero has a new position now, we need to draw the Hero on his new position in order to see it. That's what happens in Draw.
Usually Update happens before Draw, and in one second Update and Draw happen about 60 times, sometimes more often, sometimes less often.
The End method is similar to the Start method. It is called exactly one time as well, just this time at the End. It's often used to free all resources again and to destory the Game Window.