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");
}
}
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");
}
}
相关文章推荐
- Cocos2d-x学习笔记(12)(CCControlSwitch开关、CCControlSlider滑动条、CCControlButton按钮)
- 我的Cocos2d-x学习笔记(十五)CCControlSlider、CCControlSwitch、CCScale9Sprite、CCControlButton
- CCControlSwitch学习笔记
- Cocos2d-x学习笔记(12)(CCControlSwitch开关、CCControlSlider滑动条、CCControlButtonbutton)
- CCControlSwitch 开关
- CCControlSlider滑动按钮学习笔记
- CCControlColourPicker学习笔记
- CCControlButton学习笔记
- 关于CCControlSwitch设置在弹窗上后的触摸优先级问题
- cocos2d-x-2.0 新增UI的使用方法(CCControlSlider、CCControlSwitch、CCControlColourPicker、ListView)
- 1cocos2dx扩展库UI控件,CCControlSlider,CCScale9Sprite(九妹图),CCControlSwitch,CCControlButton
- Cocos2D-x 用CCControlSwitch设置音乐的开关
- cocos2dx CCControlSwitch
- cocos2dx CCControlSwitch
- cocos2dx-CCControlSwitch
- cocos2dx 开关 CCControlSwitch
- cocos2d学习之CCControl
- CCControlSwitch 的使用
- 7、Cocos2d-X 游戏编程之------CCControlSwitch的实现
- cocos2d-x 菜鸟学习笔记八(界面控件之CCControl控件)