Creating menus
In this recipe, we will create a menu. A menu has various buttons such as a start button and a pause button. A Menu is a very important component for any game and they are really useful too. The steps to use a menu are little complex. In this recipe, we will have a glance over creating menus to understand its complexity and to get used to them.
Getting ready
We prepared the following image as a button image and added them to the Resources/res
folder in our project. We will use the following image of the button to use it as menu:
How to do it...
Firstly, we will create a simple menu that has one item for a button. We will use the item1.png
file as the button image. Create the menu by using the code here.
auto normalItem = Sprite::create("res/item1.png"); auto selectedItem = Sprite::create("res/item1.png"); selectedItem->setColor(Color3B::GRAY); auto item = MenuItemSprite::create(normalItem, selectedItem, [](Ref* sender){ CCLOG("tapped item"); }); auto size = Director::getInstance...