UI开发之控件类-CCControlColourPicker

bool HelloWorld::init()
{
    bool bRet = false;
    do 
    {
       
        CC_BREAK_IF(! CCLayer::init());

		//设置一个显示字符串的label
		CCLabelTTF * title = CCLabelTTF::create("#128128128","Arial",32);
		title->setPosition(ccp(240,280));
		//设置label的tag为1,方便以后获取
		this->addChild(title,1,1);

		//这里有一个问题需要注意,在create之前,应该在resource目录下新建一个文件夹叫做extensions,然后把源代码中
		//和CCControlColourPicker相关的资源导入进去,其实就俩个而已
		CCControlColourPicker * colorPicker = CCControlColourPicker::create();
		colorPicker->setColor(ccc3(128,128,128));

		//设置一张背景图片,但是却不起作用,至今没解决,有谁解决了,说一声
		//colorPicker->setBackground(CCSprite::create("HelloWorld.png"));

		//为colorPicker添加事件监听函数
		colorPicker->addTargetWithActionForControlEvents(this,cccontrol_selector(HelloWorld::colorValueChanged),
    		CCControlEventValueChanged);

		//设置位置
		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.1.4,说以pPicker调用的是getColor函数,据本人查看他人的
	//博客,他们都是用的getColorValue函数,应该是早一点的版本
	title->setString(CCString::createWithFormat("#%03d%03d%03d",pPicker->getColor().r,pPicker->getColor().g,
		pPicker->getColor().b)->getCString());
 }


  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值