O'Reilly logo

Cocos2d-x Game Development Essentials by Gareth Jones, Arutosh Gurung, Frahaan Hussain

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Coding the menus in the Main Menu scene

The main menu requires a simple menu system for navigation between itself and the game screen. Menu item images will be used to display a game title and to display the button that the user can interact with to maneuver between scenes.

Add the following code to the init() method:

auto menuTitle = MenuItemImage::create("MainMenuScreen/Game_Title.png", "MainMenuScreen/Game_Title.png");

auto playItem = MenuItemImage::create("MainMenuScreen/Play_Button.png", "MainMenuScreen/Play_Button(Click).png", CC_CALLBACK_1(MainMenu::GoToGameScene, this));

auto menu = Menu::create(menuTitle, playItem, NULL);
menu->alignItemsVerticallyWithPadding(visibleSize.height / 4);
this->addChild(menu);

Menu item images have three states: ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required