Cocos2d-x UI開發(fā)之CCControlColourPicker控件類使用實(shí)例
CCControlColourPicker實(shí)現(xiàn)顏色拾取器的功能。關(guān)于控件使用時(shí)的一些配置,請(qǐng)參見文章:UI開發(fā)之控件類-CCControlButton。下邊來看源代碼。
bool HelloWorld::init()
{
  bool bRet = false;
  do
  {
    CC_BREAK_IF(! CCLayer::init());
		//設(shè)置一個(gè)顯示字符串的label
		CCLabelTTF * title = CCLabelTTF::create("#128128128","Arial",32);
		title->setPosition(ccp(240,280));
		//設(shè)置label的tag為1,方便以后獲取
		this->addChild(title,0,1);
		//這里有一個(gè)問題需要注意,在create之前,應(yīng)該在resource目錄下新建一個(gè)文件夾叫做extensions,然后把源代碼中
		//和CCControlColourPicker相關(guān)的資源導(dǎo)入進(jìn)去
		CCControlColourPicker * colorPicker = CCControlColourPicker::create();
		colorPicker->setColor(ccc3(128,128,128));
		//設(shè)置一張背景圖片,但是卻不起作用,至今沒解決,有誰解決了,說一聲
		//colorPicker->setBackground(CCSprite::create("HelloWorld.png"));
		//為colorPicker添加事件監(jiān)聽函數(shù)
		colorPicker->addTargetWithActionForControlEvents(this,cccontrol_selector(HelloWorld::colorValueChanged),
  		CCControlEventValueChanged);
		//設(shè)置位置
		colorPicker->setPosition(ccp(240,160));
		this->addChild(colorPicker);
    bRet = true;
  } while (0);
  return bRet;
}
void HelloWorld::colorValueChanged(CCObject * pSender,CCControlEvent controlEvent)
 {
	CCLabelTTF * title = (CCLabelTTF *)this->getChildByTag(1);
	CCControlColourPicker * pPicker = (CCControlColourPicker *)pSender;
	//這里需要注意了,本人用的cocos2d-x的版本是2.2,應(yīng)該用pPicker調(diào)用getColor函數(shù),但據(jù)本人查看他人的
	//博客,他們都是用的getColorValue函數(shù),他們應(yīng)該是早一點(diǎn)的版本
	title->setString(CCString::createWithFormat("#%03d%03d%03d",pPicker->getColor().r,pPicker->getColor().g,
		pPicker->getColor().b)->getCString());
 }
上一篇:Cocos2d-x學(xué)習(xí)筆記之開發(fā)環(huán)境搭建
欄 目:C語言
下一篇:Cocos2d-x中使用CCScrollView來實(shí)現(xiàn)關(guān)卡選擇實(shí)例
本文標(biāo)題:Cocos2d-x UI開發(fā)之CCControlColourPicker控件類使用實(shí)例
本文地址:http://www.jygsgssxh.com/a1/Cyuyan/3386.html
您可能感興趣的文章
- 01-10fatal error LNK1104: 無法打開文件“l(fā)ibc.lib”的解決方法
 - 01-10深入探討linux下進(jìn)程的最大線程數(shù)、進(jìn)程最大數(shù)、進(jìn)程打開的文
 - 01-10DHCP:解析開發(fā)板上動(dòng)態(tài)獲取ip的2種實(shí)現(xiàn)方法詳解
 - 01-10ubuntu中打開終端的三種解決方法
 - 01-10C語言文件操作函數(shù)大全(超詳細(xì))
 - 01-10基于linux下C開發(fā)中的幾點(diǎn)技術(shù)經(jīng)驗(yàn)總結(jié)
 - 01-10C++ 創(chuàng)建桌面快捷方式 開始菜單的實(shí)現(xiàn)代碼
 - 01-10C++函數(shù)重載的深入解析
 - 01-10C++ 在堆上開辟與釋放二維、三維指針詳細(xì)解析
 - 01-10VC++開發(fā)中完美解決頭文件相互包含問題的方法解析
 


閱讀排行
- 1C語言 while語句的用法詳解
 - 2java 實(shí)現(xiàn)簡(jiǎn)單圣誕樹的示例代碼(圣誕
 - 3利用C語言實(shí)現(xiàn)“百馬百擔(dān)”問題方法
 - 4C語言中計(jì)算正弦的相關(guān)函數(shù)總結(jié)
 - 5c語言計(jì)算三角形面積代碼
 - 6什么是 WSH(腳本宿主)的詳細(xì)解釋
 - 7C++ 中隨機(jī)函數(shù)random函數(shù)的使用方法
 - 8正則表達(dá)式匹配各種特殊字符
 - 9C語言十進(jìn)制轉(zhuǎn)二進(jìn)制代碼實(shí)例
 - 10C語言查找數(shù)組里數(shù)字重復(fù)次數(shù)的方法
 
本欄相關(guān)
- 04-02c語言函數(shù)調(diào)用后清空內(nèi)存 c語言調(diào)用
 - 04-02func函數(shù)+在C語言 func函數(shù)在c語言中
 - 04-02c語言的正則匹配函數(shù) c語言正則表達(dá)
 - 04-02c語言用函數(shù)寫分段 用c語言表示分段
 - 04-02c語言中對(duì)數(shù)函數(shù)的表達(dá)式 c語言中對(duì)
 - 04-02c語言編寫函數(shù)冒泡排序 c語言冒泡排
 - 04-02c語言沒有round函數(shù) round c語言
 - 04-02c語言分段函數(shù)怎么求 用c語言求分段
 - 04-02C語言中怎么打出三角函數(shù) c語言中怎
 - 04-02c語言調(diào)用函數(shù)求fibo C語言調(diào)用函數(shù)求
 
隨機(jī)閱讀
- 04-02jquery與jsp,用jquery
 - 01-10使用C語言求解撲克牌的順子及n個(gè)骰子
 - 01-10C#中split用法實(shí)例總結(jié)
 - 08-05dedecms(織夢(mèng))副欄目數(shù)量限制代碼修改
 - 08-05DEDE織夢(mèng)data目錄下的sessions文件夾有什
 - 08-05織夢(mèng)dedecms什么時(shí)候用欄目交叉功能?
 - 01-10delphi制作wav文件的方法
 - 01-11Mac OSX 打開原生自帶讀寫NTFS功能(圖文
 - 01-11ajax實(shí)現(xiàn)頁面的局部加載
 - 01-10SublimeText編譯C開發(fā)環(huán)境設(shè)置
 


