您的位置:首页 > 其它

CCControlColourPicker学习笔记

2013-01-30 14:33 232 查看
我的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");

崩溃啊。。。。。。。。。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐