Transitions between scenes

In a previous section, you learned how to create a menu with cocos2d's built-in classes. The menu of our tower defense game will be very similar, since it follows the same steps. It will be implemented in a separate module, named mainmenu:

class MainMenu(cocos.menu.Menu): def __init__(self): super(MainMenu, self).__init__('Tower Defense') self.font_title['font_name'] = 'Oswald' self.font_item['font_name'] = 'Oswald' self.font_item_selected['font_name'] = 'Oswald' self.menu_anchor_y = 'center' self.menu_anchor_x = 'center' items = list() items.append(MenuItem('New Game', self.on_new_game)) items.append(ToggleMenuItem('Show FPS: ', self.show_fps, director.show_FPS)) items.append(MenuItem('Quit', pyglet.app.exit)) self.create_menu(items, ...

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.