我的cocos2d-x版本是2.1.0。CCControlColourPicker的源码我就直接贴这了,以后忘了的时候直接拿过来用就好,自己亲自测试,有问题请留言,谢谢。2d-x学习中。。。。。。。。。。。
CCControlColourPicker *colourPicker = CCControlColourPicker::create();
colourPicker->setColor(ccc3(37, 46, 252));
colourPicker->setPosition(ccp (240, 160));
colourPicker->setBackground(CCSprite::create("HelloWorld.png"));
colourPicker->setEnabled(false);
// Add it to the layer
this->addChild(colourPicker);
//
// Add the target-action pair
colourPicker->addTargetWithActionForControlEvents(this, cccontrol_selector(HelloWorld::colourValueChanged), CCControlEventValueChanged);
回调函数
void HelloWorld::colourValueChanged(CCObject *sender)
{
CCControlColourPicker* pPicker = (CCControlColourPicker*)sender;
std::string str = CCString::createWithFormat("#%02X%02X%02X",pPicker->getColo r().r, pPicker->getColor().g, pPicker->getColor().b)->getCString();
CCLog("CCControlColourPicker value = %s",str.c_str());
}
说一下我用的时候的问题,我第一次用的时候是把sample里边的extensions文件夹拖到项目资源中,然后将
CCControlColourPicker的cpp文件中
bool CCControlColourPicker::init()里边的资源名改掉才成功的,不知道有没有同样问题的原来的是
CCSpriteFrameCache::sharedSpriteFrameCache()->addSpriteFramesWithFile("extensions/CCControlColourPickerSpriteSheet.plist");
CCSpriteBatchNode *spriteSheet = CCSpriteBatchNode::create("extensions/CCControlColourPickerSpriteSheet.png");
我修改为
CCSpriteFrameCache::sharedSpriteFrameCache()->addSpriteFramesWithFile("CCControlColourPickerSpriteSheet.plist");
CCSpriteBatchNode *spriteSheet = CCSpriteBatchNode::create("CCControlColourPickerSpriteSheet.png");
崩溃啊。。。。。。。。。