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

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

2014-10-07 19:58 337 查看


 

7、CCControlSwitch的实现方法

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;

 

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
相关文章推荐