[Independent developer er Cocos2d-x practice 009] Cocos2dx menu item CCMenu use, cocos2d-xccmenu

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.