Cocos2d-x Study Notes (3) menu items

Source: Internet
Author: User

The cocos2d-x provides a variety of menu items, including: CCMenuItemLable, CCMenuItemSprite, temperature, temperature, and CCMenuItemImage. They all inherit CCMenuItem, the inheritance diagram is as follows: CCMenuItemLable: mainly including labels and labels. Usage: [cpp] usage: setFontName ("Marker Felt"); CCMenuItemFont: setFontSize (34); usage * pCloseItemFont = CCMenuItemFont: create ("CloseFont", this, menu_selector (HelloWorld: menuCloseCallback); pCloseItemFont-> setPosition (ccp (CCDirector: sharedDirector ()-> getWinSize (). width-100, 20); "CloseFont" is the text menu_selector (HelloWorld: menuCloseCallback) displayed in the menu is a callback function. After clicking the menu, it will call menuCloseC. Allback () function setFontName sets the font of the displayed text setFontSize sets the font size of the displayed text CCMenuItemAtlasFont: [cpp] CCLabelAtlas * pLabelAtlas = CCLabelAtlas: create ("0123456789", "labelatlas ", 16,24 ,'. '); // CCMenuItemLabel * pAtlasFont = CCMenuItemLabel: create (pLabelAtlas, this, menu_selector (HelloWorld: menuCloseCallback) has been mentioned in the previous article )); pAtlasFont-> setPosition (ccp (CCDirector: sharedDirector ()-> getWinSize (). width/2,200); pAtlas Font-> setDisabledColor (ccc3 (32, 32, 64); // The color pAtlasFont when disabled-> setColor (ccc3 (200,200,255 )); // The display color CCMenuItemAtlasFont is used to generate a menu item through the png file, that is, the image corresponding to the configuration file can also be used with the following :: create ("HelloWorld", "dmTest. fnt "); CCMenuItemLabel * pBMFont = CCMenuItemLabel: create (pLabelBMFont, this, menu_selector (HelloWorld: menuCloseCallback); pBMFont-> setPosition (ccp (CCDire Ctor: sharedDirector ()-> getWinSize (). width/2,160); pBMFont-> setScale (0.8f); because the font size cannot be set, use the setScale function to scale CCMenuItemSprite: Image menu: including CCMenuItemImage, you can encapsulate the image to enter the menu item: [cpp] CCSprite * pSt1 = CCSprite: create ("Normal.png"); // CCSprite is the genie class CC_BREAK_IF (! PSt1); CCSprite * pSt2 = CCSprite: create ("Selected.png"); CC_BREAK_IF (! PSt2); CCSprite * pSt3 = CCSprite: create ("Disabled.png"); CC_BREAK_IF (! PSt3) vertex * pSprites = CCMenuItemSprite: create (pSt1, pSt2, pSt3, this, menu_selector (HelloWorld: menuCloseCallback); pSprites-> setPosition (ccp (CCDirector :: sharedDirector ()-> getWinSize (). width-20, 60); CCMenuItemImage: [cpp] CCMenuItemImage * pCloseItem = condition: create ("CloseNormal.png", "CloseSelected.png", this, menu_selector (HelloWorld :: menuCloseCallback); CC_BREAK_IF (! PCloseItem); pCloseItem-> setPosition (CCDirector: sharedDirector ()-> getWinSize (). width-20, 20); CCMenuItemToggle: Any CCMenuItem can be encapsulated. As a switch button, its parameters are variable, that is to say, you can encapsulate multiple [cpp] at once. // zookeeper * pToggle = secret: createWithTarget (this, menu_selector (HelloWorld: menuCloseCallback), CCMenuItemImage: create ", "testToggle2.png"), CCMenuItemImage: create ("tes TToggle2.png "," testToggle.png "), NULL); pToggle-> setPosition (ccp (CCDirector: shareddire()-> getWinSize (). width-350, 20); finally, you need to Create a menu to add all menu items to [cpp] // Create a menu with the "close" menu item, it's an auto release object. CCMenu * pMenu = CCMenu: create (pCloseItem, pCloseItemFont, pCloseItemLabel, pToggle, pSprites, pAtlasFont, NULL); pMenu-> setPosition (CCPointZero); cancel (! PMenu); // Add the menu to HelloWorld layer as a child layer. this-> addChild (pMenu, 1); [cpp] void HelloWorld: menuCloseCallback (CCObject * pSender) // The menu item callback function {// "close" menu item clicked CCDirector:: sharedDirector ()-> end ();}

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.