滑动栏:
Slider * slider = Slider::create();
slider->loadBarTexture("sliderTrack.png");//设置滑动栏的背景图片slider->loadSlidBallTextures("sliderThumb.png","sliderThumb.png",""); //滑动栏的滑动按钮图片
slider->loadProgressBarTexture("sliderProgress.png"); //滑动栏的进度图片
slider->setPosition(Vec2(visibleSize.width/2 + origin.x,visibleSize.height/2 + origin.y + 100));
slider->addEventListener(CC_CALLBACK_2(HelloWorld::sliderEvent,this)); //设置事件监听函数
this->addChild(slider);
void HelloWorld::sliderEvent(Ref * pSender,Slider::EventType type) { if (type == Slider::EventType::ON_PERCENTAGE_CHANGED) { Slider * slider = dynamic_cast<Slider *>(pSender); int percent = slider->getPercent();//获取当前滑动的百分比 auto label = static_cast<Label *>(getChildByTag(11)); label->setString(String::createWithFormat("Perfecnt %d",percent)->getCString());//使用该百分比 } }