The cocos2d-x-2.0 has added several new UI controls. Here I will introduce the commonly used methods of using these UI controls (cccontrolslider, cccontrolswitch, cccontrolcolourpicker)

Source: Internet
Author: User
Tags addchild

Monkey original, reprinted. Reprinted Please note: Reprinted from cocos2d Development Network --cocos2dev.com, thank you!

Original address: http://www.cocos2dev.com /? P = 252

The cocos2d-x-2.0 has added several new UI controls. Here I will introduce how to use these commonly used UI controls (cccontrolslider, cccontrolswitch, cccontrolcolourpicker, listview.

1. cccontrolslider

// Slidercccontrolslider * slider = cccontrolslider: sliderwithfiles ("slidertrack2.png", "sliderprogress2.png", "Callback"); // Add the callback function slider-> callback (this, menu_selector (helloworld:: actionslider), cccontroleventvaluechanged); slider-> setposition (CCP (size. width *. 8, size. height *. 2); // The minimum and maximum values of the silder slider-> setminimumvalue (0.0f); slider-> setmaximumvalue (100366f ); // The current slider value slider-> setvalue (50366f); addchild (slider );

Callback function:

Void helloworld: actionslider (ccobject * psender) {cccontrolslider * psliderctl = (cccontrolslider *) psender; cctime scale; scale = psliderctl-> getvalue (); // current slider value cclog ("cccontrolslider value = % F", scale );}

Ii. cccontrolswitch

// Switch buttoncccontrolswitch * switchcontrol = cccontrolswitch: switchwithmasksprite (ccsprite: spritewithfile ("switch-mask.png"), ccsprite: spritewithfile ("switch-on.png"), ccsprite :: spritewithfile ("switch-off.png"), ccsprite: spritewithfile ("switch-thumb.png"), cclabelttf: labelwithstring ("on", "Arial-boldmt", 16), cclabelttf :: labelwithstring ("off", "Arial-boldmt", 16); switchcontrol-> setposition (CCP (size. width *. 8, size. height *. 35); // callback function switchcontrol-> addtargetwithactionforcontrolevents (this, menu_selector (helloworld: callbackswitch), cccontroleventvaluechanged); addchild (switchcontrol); callbackswitch (switchcontrol );

Callback function:

void HelloWorld::callbackSwitch(CCObject* pSender){CCControlSwitch* pSwitch = (CCControlSwitch*)pSender;if (pSwitch->getIsOn()){CCLog("CCControlSwitch value = ON");} else{CCLog("CCControlSwitch value = OFF");}}

Iii. cccontrolcolourpicker

//clolor pickerCCControlColourPicker *colourPicker = CCControlColourPicker::colourPicker();colourPicker->setColor(ccc3(37, 46, 252));colourPicker->setPosition(ccp (size.width*.8, size.height*.7));colourPicker->addTargetWithActionForControlEvents(this, menu_selector(HelloWorld::colourValueChanged), CCControlEventValueChanged);addChild(colourPicker);

Callback function:

void HelloWorld::colourValueChanged(CCObject *sender){CCControlColourPicker* pPicker = (CCControlColourPicker*)sender;std::string str = CCString::stringWithFormat("#%02X%02X%02X",pPicker->getColorValue().r, pPicker->getColorValue().g, pPicker->getColorValue().b)->getCString();CCLog("CCControlColourPicker value = %s",str.c_str());}

Iv. listview

A little long. Open a separate page and click to view listview usage>

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.