Adding a main menu

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 ...

Get Python Game Programming By Example now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.