cocos2d-x CCControlPotentiometer 圆形音量按钮

前端之家收集整理的这篇文章主要介绍了cocos2d-x CCControlPotentiometer 圆形音量按钮前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
#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

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