您的位置:首页 > 移动开发 > Cocos引擎

cocos2dx 开关 CCControlSwitch

2013-03-31 20:06 399 查看
//
CCLabelTTF * label1 = CCLabelTTF::create("开", "Arial-BodMT", 16);
CCLabelTTF * label2 = CCLabelTTF ::create("关", "Arial-BodMT", 16);
// 创建CCControlSwitch 开关
// 参数1: 掩饰底图
// 参数2 作为打开状态
// 参数3 作为关闭状态
// 参数4 作为开关触发图
// 参数5 作为打开的文字
// 参数6 作为关闭的文字
CCControlSwitch * pSwitch = CCControlSwitch ::create(CCSprite::create("switch-mask.png"), CCSprite::create("switch-on.png"), CCSprite::create("switch-on.png"), CCSprite::create("switch-off.png"),label1,label2);
// CCControlSwitch * pSwitch = CCControlSwitch::create(<#cocos2d::CCSprite *maskSprite#>, <#cocos2d::CCSprite *onSprite#>, <#cocos2d::CCSprite *offSprite#>, <#cocos2d::CCSprite *thumbSprite#>)
pSwitch->setPosition(ccp(200, 200));
// 设置关闭状态
pSwitch->setOn(false);
// 可操作
pSwitch->setEnabled(true);
// 获取是否打开
CCLOG("是否打开%i",pSwitch->isOn());
// 获取当前开关状态是否为手动拖动开关进行的
CCLOG("关状态是否为手动拖动开关 %i",pSwitch->hasMoved());
//
// 输出
CCLabelTTF * la = CCLabelTTF::create(" ", "Arial-BodMT", 16);
la->setPosition(ccp(200, 100));
la->setString(CCString::createWithFormat("%i",pSwitch->hasMoved())->getCString());
addChild(la);
addChild(pSwitch);
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: