#include "cocos-ext.h"
USING_NS_CC_EXT;
CCScene * circleButton::scene()
{
CCScene * s = CCScene::create();
CCLayer * layer = circleButton::create();
s->addChild(layer);
return s;
}
bool circleButton::init()
{
bool bRet = false;
do
{
CC_BREAK_IF(!CCLayer::init());
//圆形按钮;
CCControlPotentiometer * potentiometer = CCControlPotentiometer::create("poleBg.png",//底座:
"bgup.png",//进度条;
"pole.png");//中心按钮;
potentiometer->setPosition(ccp(200,200));
addChild(potentiometer);
//添加监听事件:监听事件不加也可以,如果想要迷彩灯效果的话,也可以用定时器来完成:schedule();
potentiometer->addTargetWithActionForControlEvents(
this,//添加onvalueChanged用来监听音量控制按钮的数值变化;音量值的范围是0-1;
cccontrol_selector(circleButton::onValueChanged),CCControlEventValueChanged);//音量改变;
bRet = true;
} while (0);
return bRet;
}
//回调函数;
void circleButton::onValueChanged(CCObject*pSender,CCControlEvent event)
{
//通过pSender参数获取按钮;
CCControlPotentiometer* potentiometer = (CCControlPotentiometer *)pSender;
CCString * valueStr = CCString::createWithFormat("%f",potentiometer->getValue());//转为数值输出;
CCLog(valueStr->getCString());
}
原文链接:https://www.f2er.com/cocos2dx/345178.html