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...