Cocos2d-x UI開(kāi)發(fā)之CCControlSwitch控件類使用實(shí)例
更新時(shí)間:2014年09月11日 10:37:10 作者:皂莢花
這篇文章主要介紹了Cocos2d-x UI開(kāi)發(fā)之CCControlSwitch控件類使用實(shí)例,本文代碼中含大量注釋講解了CCControlSwitch控件類的使用,需要的朋友可以參考下
CCControlSwitch是開(kāi)關(guān)按鈕,關(guān)于控件使用時(shí)的一些配置,請(qǐng)參見(jiàn)文章:UI開(kāi)發(fā)之控件類-CCControlButton。以下的演示中出現(xiàn)的key和value代表什么意思,知道的人說(shuō)一聲。

bool HelloWorld::init()
{
bool bRet = false;
do
{
CC_BREAK_IF(! CCLayer::init());
//參數(shù)就不說(shuō)了,看一下你的資源文件就明白了
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));
//設(shè)置位置
controlSwitch->setPosition(ccp(240,160));
//這個(gè)函數(shù)對(duì)應(yīng)初始時(shí),開(kāi)關(guān)的狀態(tài)是開(kāi)還是關(guān)。
controlSwitch->setOn(true);
//這個(gè)函數(shù)對(duì)應(yīng)開(kāi)關(guān)能否使用。
controlSwitch->setEnabled(true);
//添加事件監(jiān)聽(tīng)
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");
}
相關(guān)文章
手把手教你實(shí)現(xiàn)一個(gè)C++單鏈表
鏈表是一種數(shù)據(jù)結(jié)構(gòu),用于數(shù)據(jù)的存儲(chǔ)。這篇文章主要為大家介紹了如何實(shí)現(xiàn)一個(gè)C++單鏈表,文中的示例代碼講解詳細(xì),感興趣的小伙伴可以嘗試一下2022-11-11
C++調(diào)用迅雷接口解析XML下載功能(迅雷下載功能)
這篇文章主要介紹了C++調(diào)用迅雷接口,封裝解析XML下載的類,功能簡(jiǎn)單,大家參考使用吧2013-11-11

