[Independent developer er Cocos2d-x practice 009] Cocos2dx menu item CCMenu use, cocos2d-xccmenu
The menus in Cocos2dx are implemented using the CCMenu/Menu class. This class is a container used to load various Menu items. The Menu items can be images or system fonts.
I will not talk about the theory, so I should first go to the Code:
CCMenuItemToggle* item1 = CCMenuItemToggle::createWithTarget(this, menu_selector(HelloWorld::menuItemToggle), CCMenuItemFont::create("on1"), CCMenuItemFont::create("off1"), CCMenuItemFont::create("on2"), CCMenuItemFont::create("off2"), CCMenuItemFont::create("on3"), CCMenuItemFont::create("off3"), CCMenuItemFont::create("on4"), CCMenuItemFont::create("off4"), NULL);CCMenuItemImage* item2 = CCMenuItemImage::create("CloseNormal.png", "CloseSelected.png", this, menu_selector(HelloWorld::menuItemToggle)); CCLabelTTF *lable = CCLabelTTF::create("CCLabelTTF", "fonts/arial", 32);CCMenuItemLabel *item3 = CCMenuItemLabel::create(lable, this, menu_selector(HelloWorld::menuItemToggle));CCMenu *menu = CCMenu::create(item1, item2, item3, NULL);menu->alignItemsVerticallyWithPadding(10);addChild(menu);menu->setPosition(visibleSize.width / 2 - 100, visibleSize.height / 2 + 100);
Define the callback function at the same time:
void HelloWorld::menuItemToggle(CCObject *pSender){CCLOG("HelloWorld::menuItemToggle");return;}
The result is as follows:
Recommendation blog:
[Csb] http://blog.csdn.net/chenqiai0/article/details/46633407
Frame Animation http://blog.csdn.net/chenqiai0/article/details/46808109
[Plist] http://blog.csdn.net/chenqiai0/article/details/46820669
Load plist http://blog.csdn.net/chenqiai0/article/details/46820979
Scale9Sprite http://blog.csdn.net/chenqiai0/article/details/46832761
Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.