Cocos2d-x UI Development Cccontrolslider control classes use instances _c languages

Source: Internet
Author: User
Tags addchild event listener

For some configuration when a control is used, see article: Control class-cccontrolbutton for UI development. Here only the source code, the inside of the comments on the control of the use of a detailed description.

BOOL Helloworld::init () {bool BRet = false; do {cc_break_if (!

		Cclayer::init ());
		Sets a label Cclabelttf * title = cclabelttf::create ("Slider value = 0.00", "Arial", 32).
		Title->setposition (CCP (240,200));

		The tag is set to 1 for easy access to This->addchild (title,0,1); These three pictures are the bottom, the progress bar, the control button Cccontrolslider * slider = cccontrolslider::create ("Slidertrack.png", "Sliderprogress.png", "SL

		Iderthumb.png ");
		Setting the maximum minimum value of the slider slider->setmaximumvalue (100);
		Slider->setminimumvalue (0); Add an event listener function to the slider slider->addtargetwithactionforcontrolevents (this,cccontrol_selector HelloWorld::
		valuechanged), cccontroleventvaluechanged);
		Set Position Slider->setposition (CCP (240,160));

		This->addchild (slider); The use of cccontrolslider to achieve the blood bar, as long as the third control button to be transparent, it will appear to be the blood volume of cccontrolslider * Slider2 = Cccontrolslider::create ("
		Slidertrack.png "," Progress.png "," sliderthumb2.png ");
		The value slider2->settouchenabled (false) which is not considered to be changed by the following function; Slider2->setmaximumvalUE (100);
		Slider2->setminimumvalue (0);
		You can add an event handler function to change its value slider2->setvalue (100) In the event handler function;
		Slider2->setposition (CCP (240,100));

    This->addchild (SLIDER2);
  BRet = true;

  while (0);
return bRet;  }//Note This function needs to pass in two parameter types void helloworld::valuechanged (Ccobject * psender,cccontrolevent controlevent) {Cccontrolslider *
	slider = (Cccontrolslider *) Psender;
	Cclabelttf * title = (Cclabelttf *) This->getchildbytag (1); When using Cclabelttf, try not to change its contents, this is for the sake of simplicity title->setstring (Ccstring::createwithformat ("Slider value =%0.02f",
 Slider->getvalue ())->getcstring ()); }

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.