Cocos2d-x3.3Final(6)Slider常用成员函数(C++)

前端之家收集整理的这篇文章主要介绍了Cocos2d-x3.3Final(6)Slider常用成员函数(C++)前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

滑动栏:

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());//使用该百分比 } }

猜你在找的Cocos2d-x相关文章