#include"ui/CocosGUI.h"
using namespace ui;
Text* displayValudLabel = Text::create("轻易动滑块","Marker Felt.ttf", 48);
displayValudLabel->setPosition(Vec2());
this->addChild(displayValudLabel);
auto slider = Slider::create();
slider->loadBarTexture("sliderTrack.png");
//设置滑动条的滚动球文理
slider->loadSlidBallTextures("sliderball.png", "sliderball.png", "");
//设置处理滑动条的进度条文理
slider->loadProgressBarTexture("sliderprogess.png");
slider->setPosition(Vec2(visibleSize.width / 2, visibleSize.height));
//添加侦听事件
slider->addEventListener([=](Ref *pSender, Slider::EventType type){
if (type ==Slider::EventType::ON_PERCENTAGE_CHANGED)
{
//获取滑动条百分比
std::string value = StringUtils::format("Prent=%d", slider->getParent());
//设置到TextLabel中
displayValudLabel->setString(value);
}
});