O'Reilly logo

Building Android Games with Cocos2d-x by Raydelto Hernandez

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

Game menus

It is very common to have menus in some part of our games, such as the main screen and the configuration screen. This framework provides us with a simple way to add menus to our games.

The following code listing shows the menu creation process:

auto closeItem = MenuItemImage::create("pause.png", "CloseSelected.png", CC_CALLBACK_1(HelloWorld::pause_pressed, this));
closeItem->setPosition(Vec2(_visibleSize.width – closeItem->getContentSize().width/2 , closeItem-> getContentSize().height/2));
auto menu = Menu::create(closeItem, nullptr);
menu->setPosition(Vec2::ZERO);
this->addChild(menu, 1);

As we can see from the previous listing, we have first created a menu item by instantiating the MenuItemImage class and passing three parameters to ...

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