Book Image

Building Android Games with Cocos2d-x

By : Raydelto Hernandez
Book Image

Building Android Games with Cocos2d-x

By: Raydelto Hernandez

Overview of this book

Table of Contents (16 chapters)
Building Android Games with Cocos2d-x
Credits
Foreword
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

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 the create method: the first parameter indicates what image should be displayed for the menu item, the second is the image that should be displayed when the image is selected, and the third parameter specifies the method that should be...