看了网上很多人关于CCControlSwitch的学习指导,发现有些问题,就自己试试,有不足之处还望指正~!
首先,在调用 CCControlSwitch时,需要
#include "cocos-ext.h"
USING_NS_CC_EXT;
然后
CCControlSwitch *switchControl = CCControlSwitch::create(
CCSprite::create("CMSliderFront.png"),
//switch开关的外框
CCSprite::create("CMSliderFront.png"),
//switch开关处于开
CCSprite::create("CMSliderFront.png"),
//switch开关处于关
CCSprite::create("gongxuntubiao.png"),
//标志的小圆点
CCLabelTTF::create("On",
"Arial-BoldMT", 16),
CCLabelTTF::create("Off",
"Arial-BoldMT", 16)
);
switchControl->setPosition(ccp(240,
160));
this->addChild(switchControl);
switchControl->addTargetWithActionForControlEvents(this,
cccontrol_selector(HelloWorld::callbackSwitch),
CCControlEventValueChanged);
callbackSwitch(switchControl);
下面是回调方法
void
HelloWorld::callbackSwitch(CCObject* pSender){
CCControlSwitch* pSwitch = (CCControlSwitch*)pSender;
if (pSwitch->isOn()){
CCLog("CCControlSwitch value = ON");
}
else{
CCLog("CCControlSwitch value = OFF");
}
}
正在学习中。。。。。。。。。。。。。。。。