Cocos2d-x Button controls Summary

Source: Internet
Author: User

CCMenu: This is an abstract concept. The CCMenuItem inheritance diagram of the container that holds the menu item CCMenuItem: Button: ButtonTest (void) {// set the font size CCMenuItemFont: setFontSize (30 ); // set the Font CCMenuItemFont: setFontName ("Courier New") based on the name; // click setTouchEnabled (true) for setting; // Font Item // parameter description: the first image name, and the second is an object (x, y, w, h) of menuitemsprite.png. It indicates that x and y represent the coordinates of the image ~ CCSprite * spriteNormal = CCSprite: create ("menuitemsprite.png", CCRectMake (2,115 *, 23); CCSprite * spriteSelected = CCSprite: create ("menuitemsprite.png ", CCRectMake (1,115*0,115, 23); CCSprite * spriteDisabled = CCSprite: create ("menuitemsprite.png", CCRectMake (*, 23); // create a CCMenuItemSprite, parameter: add three States CCSprite, add item1 nodes, register and return listening CCMenuItemSprite * item1 = parameters: create (spriteNormal, spriteSelected, spriteDisabled, this, menu_selector (MenuTestLayer :: menuCallback); // create a CCMenuItemImage with the following parameters: Same as CCMenuItem * item2 = CCMenuItemImage: create ("SendScoreButton.png", "success", this, menu_selector (MenuTestLayer :: menuCallback2); // create a CCLabelAtlas tag (Atlas generally refers to an image set), parameter: content (image resource exists, if it does not exist, it is not displayed), image, width, CCLabelAtlas * labelAtlas = CCLabelAtlas: create ("0123456789", "fonts/labelatlas.png", 16, 24 ,'. '); // create a worker label named * item3 = CCMenuItemLabel: create (labelAtlas, this, menu_selector (MenuTestLayer: menuCallbackDisabled); item3-> setDisabledColor (ccc3 (32, 32, 64); // set the color that cannot be clicked (usually gray) item3-> setColor (ccc3 (200,200,255 )); // set the item3 tag color // create a CCMenuItemFont * item4 = metric: create ("I toggle enable items", this, menu_selector (MenuTestLayer: menuCallbackEnable )); item4-> setFontSizeObj (20); item4-> setFontName ("Marker Felt"); // create a CCLabelBMFont tag, parameter: content, font configuration fnt file CCLabelBMFont * label = CCLabelBMFont:: create ("configuration", "fonts/bitmapFontTest3.fnt"); CCMenuItemLabel * item5 = CCMenuItemLabel: create (label, this, menu_selector (MenuTestLayer: menuCallbackConfig )); item5-> setScale (0.8f); // create a CCMenuItemFont: setFontName ("Marker Felt"); optional * item6 = CCMenuItemFont: create ("Priority Test", this, menu_selector (MenuTestLayer: Queue); // create a CCMenuItemFont * item7 = queue: create ("Quit", this, menu_selector (MenuTestLayer: onQuit )); // Add a color loop change animation for CCMenuItemFon .... item7 is also a subclass of the parent class CCNode. You can also add an animation. CCActionInterval * color_action = CCTintBy: create (0.5f, 0,-255,-255 ); CCActionInterval * color_back = color_action-> reverse (); CCFiniteTimeAction * seq = CCSequence: create (color_action, color_back, NULL); item7-> runAction (CCRepeatForever :: create (CCActionInterval *) seq); // create a CCMenu menu. Other menu items can be considered as CCMenu * menu = CCMenu: create (item1, item2, item3, item4, item5, item6, item7, NULL); menu-> alignItemsVertically (); // it can be understood as setting to vertical arrangement // menu-> alignItemsHorizontally (); // horizontal arrangement // elastic effect CCSize s = CCDirector: sharedDirector ()-> getWinSize (); int I = 0; CCNode * child; CCArray * pArray = menu-> getChildren (); CCObject * pObject = NULL; // convert the object in pArray to a CCObject object, and obtain the coordinate information such as CCARRAY_FOREACH (pArray, pObject) {if (pObject = NULL) break; child = (CCNode *) pObject; CCPoint dstPoint = child-> getPosition (); int offset = (int) (s. width/2 + 50); if (I % 2 = 0) offset =-offset; child-> setPosition (CCPointMake (dstPoint. x + offset, dstPoint. y); child-> runAction (CCEaseElasticOut: create (CCMoveBy: create (2, CCPointMake (dstPoint. x-offset, 0), 0.35f); I ++;} m_disabledItem = item3; item3-> retain (); m_disabledItem-> setEnabled (false ); addChild (menu); menu-> setPosition (ccp (s. width/2, s. height/2 ));}

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.