本文共 1047 字,大约阅读时间需要 3 分钟。
2.0版本后扩展了新的一些功能,使用这些组件时需要把相关的lib等依赖进来,还有相关的头文件
#include "cocos-ext.h"
using namespace cocos2d::extension;
(1)调用代码(HelloWorldLayer.cpp中)
//5. Add a the slider// Slider CCControlSlider *slider = CCControlSlider::create("sliderTrack.png","sliderProgress.png" ,"sliderThumb.png"); slider->setPosition(ccp(size.width*0.8, size.height*0.2) ); //silder的最小值和最大值 slider->setMinimumValue(0.0f); slider->setMaximumValue(100.0f); //slider的当前值 slider->setValue(50.0f);// When the value of the slider will change, the given selector will be call//添加回调函数 slider->addTargetWithActionForControlEvents(this,cccontrol_selector(HelloWorld::valueChanged),CCControlEventValueChanged);this->addChild(slider);(2)回调函数
// Slider回调函数HelloWorldvoid HelloWorld::valueChanged(CCObject *sender, CCControlEvent controlEvent){CCControlSlider* SliderCtl = (CCControlSlider*)sender; float scale; scale = SliderCtl->getValue(); //slider的当前值 CCLog("CCControlSlider value = %f",scale); }
使用时,在回调函数里根据scale值来进行自己需要的处理