cocos2dx CCControlSlider 滑动条

前端之家收集整理的这篇文章主要介绍了cocos2dx CCControlSlider 滑动条前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
  1. //滑动条
  2. CCControlSlider * slider = CCControlSlider ::create("sliderBg.png","sliderProgress.png","sliderThumb.png");
  3. slider->setPosition(ccp(200,170));
  4. // 设置滑动条最大值
  5. slider->setMaximumValue(100);
  6. // 设置滑动条最小值
  7. slider->setMinimumValue(0);
  8. addChild(slider,921);
  9. // 设置监听 , 但滑动条的值发生变化后 , 会相应 valueChanged 函数
  10. //CCControlEventValueChanged值改变
  11. slider->addTargetWithActionForControlEvents(this,cccontrol_selector(HelloWorld::valueChanged),CCControlEventValueChanged);
  12. // 用于展示当前滑动条的滑动值
  13. CCLabelTTF * label = CCLabelTTF ::create();
  14. label->setColor(ccc3(255,0));
  15. label->setPosition(ccp(200,200));

  16. label->setString(CCString::createWithFormat("滑动条当前值= %0.02f",slider->getValue())->getCString());
  17. addChild(label,922);
复制代码



  1. void HelloWorld::valueChanged()
  2. {
  3. // 利用tag 来确定
  4. CCControlSlider *slider = (CCControlSlider * )this->getChildByTag(921);
  5. CCLabelTTF * label =(CCLabelTTF * )this->getChildByTag(922);
  6. label->setString(CCString::createWithFormat("滑动条的当前值 = %.02f",serif; font-size:12px; line-height:1.8em">
  7. }
原文来自: http://www.cnblogs.com/linux-ios/archive/2013/04/01/2994570.html

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