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 Game scene

The Game scene requires a simple menu system to pause the game. A menu item image will be used to display the button that the user can interact with in order to pause the game and load the Pause scene.

Add the following code to the init() method:

auto pauseItem = MenuItemImage::create("GameScreen/Pause_Button.png", "GameScreen/Pause_Button(Click).png", CC_CALLBACK_1(GameScreen::GoToPauseScene, this)); pauseItem->setPosition(Point(pauseItem->getContentSize().width - (pauseItem->getContentSize().width / 4) + origin.x, visibleSize.height - pauseItem->getContentSize().height + (pauseItem->getContentSize().width / 4) + origin.y)); auto menu = Menu::create(pauseItem, NULL); menu->setPosition(Point::ZERO); this->addChild(menu); ...

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