Game Development Reference
In-Depth Information
Figure 8-12.
Configuring colliders to detect mouse down events
Handling Button Presses
The buttons for the main menu GUI are almost empty shells. Their task is simply to post notifications
into the event system when clicks are made and the menu is visible. The real “core” functionality
to be invoked from button presses will actually occur in other classes listening for the button-press
events. The main menu supports the functions:
Restart
(to restart the level),
Load Game
(to restore
a previously saved game),
Save Game
(to save the current game state to persistent storage),
Cancel
(to close the menu and resume the game), and
Exit
(to terminate the game). The next chapter
will consider the implementation of loading and saving games. In this section, we'll perform the
Restart, Cancel, and Exit feature set. Actually, considering Listing 8-3, the
GUIOptions
class already
features the code we need to respond to menu cancelling. At line 26, the menu registers for the
HideOptions
event, which is invoked when the Cancel button is pressed. The remaining two features,
Restart and Exit can be added into the GameManager (see Listing 8-5 for a revised
Start
function
for
GameManager
class, as well as the relevant methods; this class is also included in the topic
companion files for
/Chapter08/
).