本文整理汇总了C++中CCControlButton::addChild方法的典型用法代码示例。如果您正苦于以下问题:C++ CCControlButton::addChild方法的具体用法?C++ CCControlButton::addChild怎么用?C++ CCControlButton::addChild使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CCControlButton
的用法示例。
在下文中一共展示了CCControlButton::addChild方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: simulateAnswerRight
void QuestionLayer::simulateAnswerRight()
{
this->unschedule(schedule_selector(QuestionLayer::timerCB));
CCDictionary* results = questionObj->rightAnswer;
for (int i=0; i<results->allKeys()->count(); i++) {
CCString* key = (CCString *)(results->allKeys()->objectAtIndex(i));
results->setObject(CCString::createWithFormat("%d", 1), key->getCString());
}
//回答完成所有正确答案
for (int i=0; i<results->allKeys()->count(); i++) {
CCString* key = (CCString *)(results->allKeys()->objectAtIndex(i));
CCControlButton* btn = (CCControlButton *)(this->getChildByTag(key->intValue()));
CCSprite* spr = CCSprite::create("star000.png");
spr->setAnchorPoint(ccp(0.5f, 0.5f));
spr->setPosition(ccp(btn->getContentSize().width/2, btn->getContentSize().height/2));
btn->addChild(spr);
CCBlink* blink = CCBlink::create(1.0f, 3);
if (i < results->allKeys()->count()-1) {
spr->runAction(blink);
} else {
CCAction* pAction = CCCallFuncND::create(this, callfuncND_selector(QuestionLayer::noticeDelegate), NULL);
spr->runAction(CCSequence::create(blink, pAction, NULL));
}
}
rightAnswer++;
if (timerCount >= timerTotal*2/3) {
rightLimit += 1;
//播放快速答题音效
GameSoundManager::shareManager()->playAnswerCool();
} else {
//播放普通答题正确音效
GameSoundManager::shareManager()->playAnswerRight();
}
isAnswerFinished = true;
}
示例2: touchDownAction
void QuestionLayer::touchDownAction(CCObject *sender, CCControlEvent controlEvent)
{
CCLOG("QuestionLayer::touchDownAction");
if (isAnswerFinished) {
return;
}
this->unschedule(schedule_selector(QuestionLayer::timerCB));
CCControlButton* button = (CCControlButton *)sender;
CCLOG("%d", button->getTag());
button->setEnabled(false);
bool bFind = false;
CCDictionary* results = questionObj->rightAnswer;
for (int i=0; i<results->allKeys()->count(); i++) {
CCString* key = (CCString *)(results->allKeys()->objectAtIndex(i));
if (key->intValue() == button->getTag()) {
results->setObject(CCString::createWithFormat("%d", 1), key->getCString());
bFind = true;
break;
}
}
if (bFind) {
//统计已经回答正确答案的数量
int rCount = 0;
for (int i=0; i<results->allKeys()->count(); i++) {
CCString* key = (CCString *)(results->allKeys()->objectAtIndex(i));
CCString* value = (CCString *)(results->objectForKey(key->getCString()));
if (value->intValue() == 1) {
rCount++;
}
}
CCLOG("rCount:%d", rCount);
if (rCount == results->allKeys()->count()) {
//回答完成所有正确答案
for (int i=0; i<results->allKeys()->count(); i++) {
CCString* key = (CCString *)(results->allKeys()->objectAtIndex(i));
CCControlButton* btn = (CCControlButton *)(this->getChildByTag(key->intValue()));
CCSprite* spr = CCSprite::create("star000.png");
spr->setAnchorPoint(ccp(0.5f, 0.5f));
spr->setPosition(ccp(button->getContentSize().width/2, button->getContentSize().height/2));
btn->addChild(spr);
CCBlink* blink = CCBlink::create(1.0f, 3);
if (i < results->allKeys()->count()-1) {
spr->runAction(blink);
} else {
CCAction* pAction = CCCallFuncND::create(this, callfuncND_selector(QuestionLayer::noticeDelegate), NULL);
spr->runAction(CCSequence::create(blink, pAction, NULL));
}
}
rightAnswer++;
if (timerCount >= timerTotal*2/3) {
rightLimit += 1;
//播放快速答题音效
GameSoundManager::shareManager()->playAnswerCool();
} else {
//播放普通答题正确音效
GameSoundManager::shareManager()->playAnswerRight();
}
isAnswerFinished = true;
} else {
CCLOG("正确答案没选完");
}
} else {
//回答错误
CCSprite* spr = CCSprite::create("arrow000.png");
spr->setAnchorPoint(ccp(0.5f, 0.5f));
spr->setPosition(ccp(button->getContentSize().width/2, button->getContentSize().height/2));
button->addChild(spr);
CCFadeIn* fadeIn = CCFadeIn::create(1.0f);
CCAction* pAction = CCCallFuncND::create(this, callfuncND_selector(QuestionLayer::noticeDelegate), NULL);
spr->runAction(CCSequence::create(fadeIn, pAction, NULL));
errorAnswer++;
isAnswerFinished = true;
//播放错误音效
GameSoundManager::shareManager()->playAnswerError();
}
}