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 ()); }