Graphical User Interface
It is now time to turn our attention to the graphical user interface, or GUI. The GUI allows us to control other elements of the game, such as starting or stopping the game, or setting various options.
In this section, you will learn how to create buttons on the screen that can be clicked by the mouse. We'll keep it simple by adding a single button to pause the game. While we are at it, we will learn important lessons about game state.
Creating a button
A button is nothing more than a texture that is being displayed on the screen. However, we have to perform some special coding to detect whether or not the button is being clicked. We will add this functionality to the sprite class so that our buttons are being handled by the same class that handles other image in our game.
We will actually create two buttons: one to Pause and one to Resume. I have used a simple graphics program to create the following two buttons:
I have saved these buttons as, you guessed it, pause...