Cocos2d-x UI開辟之CCControlSwitch控件類應用實例。本站提示廣大學習愛好者:(Cocos2d-x UI開辟之CCControlSwitch控件類應用實例)文章只能為提供參考,不一定能成為您想要的結果。以下是Cocos2d-x UI開辟之CCControlSwitch控件類應用實例正文
CCControlSwitch是開關按鈕,關於控件應用時的一些設置裝備擺設,請拜見文章:UI開辟之控件類-CCControlButton。以下的演示中湧現的key和value代表甚麼意思,曉得的人說一聲。
bool HelloWorld::init()
{
bool bRet = false;
do
{
CC_BREAK_IF(! CCLayer::init());
//參數就不說了,看一下你的資本文件就明確了
CCControlSwitch * controlSwitch = 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));
//設置地位
controlSwitch->setPosition(ccp(240,160));
//這個函數對應初始時,開關的狀況是開照樣關。
controlSwitch->setOn(true);
//這個函數對應開關可否應用。
controlSwitch->setEnabled(true);
//添加事宜監聽
controlSwitch->addTargetWithActionForControlEvents(this,cccontrol_selector(HelloWorld::valueChanged),
CCControlEventValueChanged);
this->addChild(controlSwitch);
bRet = true;
} while (0);
return bRet;
}
void HelloWorld::valueChanged(CCObject * pSender,CCControlEvent controlEvent)
{
CCControlSwitch * controlSwitch = (CCControlSwitch *)pSender;
CCLog("click");
}