7、Cocos2d-X 游戏编程之------CCControlSwitch的实现

来源:互联网 发布:手机淘宝账号交易平台 编辑:程序博客网 时间:2024/06/05 20:32


 

7CCControlSwitch的实现方法

boolHelloWorld::init()

 

{

  

if (!CCLayer::init() )

   

{

       

return false;

   

}

    

 

   

CCControlSwitch*pSwitch= CCControlSwitch::create(

                                                      

CCSprite::create("switch-mask.png"),

                                                     

 CCSprite::create("switch-on.png"),

                                                     

 CCSprite::create("switch-off.png"),

                                                      

CCSprite::create("switch-thumb.png"),

                                                      

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

                                                      

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

    );

  

 pSwitch->setPosition(ccp(200,200));

   

//设置关闭状态

   

pSwitch->setOn(false);

   

//设置可操作

   

pSwitch->setEnabled(true);

  

 //获取是否为打开(on

   

CCLOG("是否打开状态:%i",pSwitch->isOn());

    

//获取当前开关状态是否为手动拖动开关进行的

   

CCLOG("是否手动拖动的开关:%i",pSwitch->hasMoved());

  

 addChild(pSwitch);

       

  

   

return true;

 

}

0 0
原创粉丝点击