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


05-02 21:54