-
Book Overview & Buying
-
Table Of Contents
Python Game Programming By Example
By :
The Space Invaders version that we developed in the previous chapter starts a new game as soon as the application is loaded. In most games, an initial screen is displayed and the player can choose between different options apart from starting a new game, such as changing the default controls or taking a look at the high scores.
The cocos.menu cocos2d module offers a Layer subclass named Menu, which serves exactly this purpose. By extending it, you can override its __init__ method and set the style of the title, the menu items, and the selected menu item.
These items are represented as a list of MenuItem instances. Once this list is instantiated, you can call the create_menu method, which builds the final menu with the actions that are executed when a menu item is selected.
While the basic MenuItem only displays a static label, there are several MenuItem subclasses for distinct input modes:
ToggleMenuItem: Toggles a Boolean optionMultipleMenuItem: Switches between multiple...
Change the font size
Change margin width
Change background colour