• 博客园logo
  • 会员
  • 周边
  • 新闻
  • 博问
  • 闪存
  • 众包
  • 赞助商
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
linux_ios
博客园    首页    新随笔    联系   管理    订阅  订阅

cocos2dx 开关 CCControlSwitch

//
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);

 

posted @ 2013-03-31 20:06  linux_ios  阅读(669)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2026
浙公网安备 33010602011771号 浙ICP备2021040463号-3