您的位置:首页 > 其它

CCControlSwitch 的学习

2014-03-12 16:45 330 查看
CCControlSwitch *pSwitch= CCControlSwitch::create(
CCSprite::create("switch-mask.png"),
//switch开关的外框
CCSprite::create("switch-on.png"),
//switch开关处于开
CCSprite::create("switch-off.png"),
//switch开关处于关
CCSprite::create("switch-thumb.png"),
//标志的小圆点
CCLabelTTF::create("开",
"Arial-BoldMT", 16),
CCLabelTTF::create("关",
"Arial-BoldMT", 16)
);
pSwitch->addTargetWithActionForControlEvent(this,
cccontrol_selector(HelloWorld::swithEvent),
CCControlEventValueChanged);
pSwitch->setPosition(ccp(200,200));
//设置关闭状态
pSwitch->setOn(false);
//设置可操作
pSwitch->setEnabled(true);
//获取是否为打开(on)
CCLOG("是否打开状态:%i",pSwitch->isOn());
//获取当前开关状态是否为手动拖动开关进行的
CCLOG("是否手动拖动的开关:%i",pSwitch->hasMoved());
addChild(pSwitch);

void HelloWorld::swithEvent(CCObject *pSender){
CCControlSwitch *controlSwith = (CCControlSwitch*)pSender;
if (controlSwith->isOn()) {
CCLOG("on");
}else{
CCLOG("close");
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: