cocos2dx CCControlSlider 滑动条
//滑动条 CCControlSlider * slider = CCControlSlider ::create("sliderBg.png", "sliderProgress.png", "sliderThumb.png"); slider->setPosition(ccp(200, 170)); // 设置滑动条最大值 slider->setMaximumValue(100); // 设置滑动条最小值 slider->setMinimumValue(0); addChild(slider,0,921); // 设置监听 , 但滑动条的值发生变化后 , 会相应 valueChanged 函数 //CCControlEventValueChanged值改变 slider->addTargetWithActionForControlEvents(this, cccontrol_selector(HelloWorld::valueChanged), CCControlEventValueChanged); // 用于展示当前滑动条的滑动值 CCLabelTTF * label = CCLabelTTF ::create(); label->setColor(ccc3(255, 0, 0)); label->setPosition(ccp(200, 200)); label->setString(CCString::createWithFormat("滑动条当前值= %0.02f",slider->getValue())->getCString()); addChild(label,0,922);
void HelloWorld::valueChanged() { // 利用tag 来确定 CCControlSlider * slider = (CCControlSlider * )this->getChildByTag(921); CCLabelTTF * label =(CCLabelTTF * )this->getChildByTag(922); label->setString(CCString::createWithFormat("滑动条的当前值 = %.02f" ,slider->getValue())->getCString()); }