Integrating the Game class
By now we already know how the
Game
class works, what a game loop is for, and how to take advantage of it. For this chapter, we take the previously used Game
class, and plug into it our newcomer World
class.
Because we obeyed a few principles, this integration is very easy and it's just a matter of having a World
object inside the
Game
class, and then letting it update and draw itself in the appropriate times.
The run() method
Our application's
main()
function has a simple job. It allocates a Game
object, and lets it run itself through the run()
method. When the run()
method exits, the program releases its resources and closes.
Therefore, it is within the run()
method that the magic happens! It is responsible for managing the famous game loop, fetching input from the window system, updating the world, and ordering the rendering of the game.
In the next chapter, events and input will be covered in depth. For now, it is only important to understand how the drawing...