cocos2dx CCControlSwitch

CCControlSwitch也是extension中的控件,本身比较简单,直接上例子

// on "init" you need to initialize your instance
bool ControlSwitch01::init()
{
    //
    // 1. super init first
    if ( !MenuLayer::init() )
    {
        return false;
    }
    
    
    CCSize size = __winSize;
    
    // Create the switch
    CCControlSwitch *switchControl = CCControlSwitch::create
    (
     CCSprite::create("extensions/switch-mask.png"),
     CCSprite::create("extensions/switch-on.png"),
     CCSprite::create("extensions/switch-off.png"),
     CCSprite::create("extensions/switch-thumb.png"),
     CCLabelTTF::create("On", "Arial-BoldMT", 16),
     CCLabelTTF::create("Off", "Arial-BoldMT", 16)
     );
    switchControl->setPosition(ccp (size.width/2, size.height/2));
    addChild(switchControl);
    
    switchControl->addTargetWithActionForControlEvents(this, cccontrol_selector(ControlSwitch01::valueChanged), CCControlEventValueChanged);
    
    return true;

}

void ControlSwitch01::valueChanged(CCObject* sender, CCControlEvent ev)
{
    CCControlSwitch *switchControl = (CCControlSwitch *)sender;
    if(switchControl->isOn())
    {
        CCLOG("This is On");
    }
    else
    {
        CCLOG("This is Off");
    }
}





转载于:https://www.cnblogs.com/new0801/p/6177169.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值