前端之家收集整理的这篇文章主要介绍了
Cocos2d-x_CCControlSwitch(开关类)介绍,
前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
bool HelloWorld::init()
{
if ( !CCLayer::init() )
{
return false;
}
CCSize winSize = CCDirector::sharedDirector()->getWinSize();
CCSprite *maskSprite = CCSprite::create("CloseNormal.png");
CCSprite *onSprite = CCSprite::create("CloseNormal.png");
CCSprite *offSprite = CCSprite::create("CloseSelected.png");
CCSprite *thumSprite = CCSprite::create("CloseNormal.png");
CCLabelTTF *onLabel = CCLabelTTF::create("开","Arial-BoldMT",16);
CCLabelTTF *offLabel = CCLabelTTF::create("关",16);
CCControlSwitch *pSwitch = CCControlSwitch::create(maskSprite,onSprite,offSprite,thumSprite,onLabel,offLabel);
pSwitch->setPosition(ccp(100,100));
pSwitch->setOn(false,true);
pSwitch->setEnabled(true);
this->addChild(pSwitch);
return true;
}