cocos2d-x扩展库CCControlSwitch的使用方法

来源:互联网 发布:unity3d基础教程 编辑:程序博客网 时间:2024/05/27 03:25

看了网上很多人关于CCControlSwitch的学习指导,发现有些问题,就自己试试,有不足之处还望指正~!


首先,在调用 CCControlSwitch时,需要

#include "cocos-ext.h"

USING_NS_CC_EXT;



然后

CCControlSwitch *switchControl = CCControlSwitch::create(

     

     CCSprite::create("CMSliderFront.png"), //switch开关的外框

     

     CCSprite::create("CMSliderFront.png"), //switch开关处于开

     

     CCSprite::create("CMSliderFront.png"), //switch开关处于关

    

     CCSprite::create("gongxuntubiao.png"), //标志的小圆点

     

     CCLabelTTF::create("On","Arial-BoldMT", 16),  

     

     CCLabelTTF::create("Off","Arial-BoldMT", 16)

     

     );

    

    switchControl->setPosition(ccp(240,160));

   this->addChild(switchControl);

    switchControl->addTargetWithActionForControlEvents(this,cccontrol_selector(HelloWorld::callbackSwitch),CCControlEventValueChanged);

    

    

   callbackSwitch(switchControl);


下面是回调方法

voidHelloWorld::callbackSwitch(CCObject* pSender){

    

    CCControlSwitch* pSwitch = (CCControlSwitch*)pSender;

    

   if (pSwitch->isOn()){

    

        CCLog("CCControlSwitch value = ON");

        

    }else{

        

        CCLog("CCControlSwitch value = OFF");

        

    } 

    


正在学习中。。。。。。。。。。。。。。。。

原创粉丝点击