动画播放方式
1. 自己写序列帧
CCSprite* pettimeSprite = CCSprite::spriteWithFile("PKF/num_1.png");
pettimeSprite->setScale(scaleX);
pettimeSprite->setPosition(ccp(width * 0.5f, pettimeSprite->getContentSize().height * scaleX * 0.56f));
this->addChild(pettimeSprite);
CCAnimation* animation = CCAnimation::animation();
for( int i=4;i<10;i++)
{
char szName[100] = {0};
sprintf(szName, "PKF/num_%d.png", i);
animation->addSpriteFrameWithFileName(szName);
}
animation->setDelayPerUnit(2.8f / 14.0f);
animation->setRestoreOriginalFrame(true);
CCAnimate* tianti_action = CCAnimate::actionWithAnimation(animation);
CCActionInterval* tianti_action_back = tianti_action->reverse();
CCActionInterval* tianti_seq = (CCActionInterval*)(CCSequence::actions(tianti_action, tianti_action_back, NULL));
CCActionInterval* tianti_rep = CCRepeat::actionWithAction((CCFiniteTimeAction*)(tianti_seq->copy()->autorelease()), -1);
pettimeSprite->runAction(tianti_rep);
//动画类CCAnimationHelper
CCSprite* succeedSprite = CCSprite::spriteWithFile("correction/correction1.png");
succeedSprite->setPosition(ccp(this->width * 0.5f,
(this->height + succeedSprite->getContentSize().height * scaleX) * 0.5f + succeedSprite->getContentSize().height * scaleX * 0.5f));
this->addChild(succeedSprite, WIN_LAYER_ORDER - 3);
CCAnimation* anim = CCAnimationHelper::animationWithFile((char*)"correction/correction", 1, 3, 0.15);
CCAnimate* animate = CCAnimate::actionWithAnimation(anim);
CCFiniteTimeAction *seq = CCSequence::actions(animate, NULL);
CCRepeatForever* repeat = CCRepeatForever::actionWithAction((CCActionInterval*)seq);
succeedSprite->runAction(repeat);
2.动画回调函数
CCAnimation* anim = CCAnimationHelper::animationWithFile((char*)"PKF/num_", 4, 6, 0.15);
CCDelayTime *stay = CCDelayTime::actionWithDuration(0.01f);
CCCallFunc* callDelay = CCCallFunc::actionWithTarget(this, callfunc_selector(ReadyScene::goToNextPage));
CCAnimate* animate = CCAnimate::actionWithAnimation(anim);
CCFiniteTimeAction *seq = CCSequence::actions(animate, stay, callDelay, NULL);
CCRepeatForever* repeat = CCRepeatForever::actionWithAction((CCActionInterval*)seq);
pettimeSprite->runAction(repeat);
3. //执行一次后消失
CCAnimation* anim = CCAnimationHelper::animationWithFile((char*)"images/answer_win_level_", 0, 4, 0.15);
CCAnimate* animate = CCAnimate::actionWithAnimation(anim);
// 在animFinished函数里设置显示状态
CCCallFunc* callEnd = CCCallFunc::actionWithTarget(this, callfunc_selector(GameAnswerLayer::animFinished));
CCFiniteTimeAction *seq = CCSequence::actions(animate, callEnd, NULL);
levelSprite->runAction(seq);
4.//1.5s内闪5下
plight = CCSprite::spriteWithFile("images/light.png");
plight->setPosition(ccp(miaokaiItem->getContentSize().width * 0.38f, miaokaiItem->getContentSize().height * 0.65f));
miaokaiItem->addChild(plight);
CCActionInterval* actionTo = CCBlink::actionWithDuration(1.5f, 5);
CCActionInterval* rep1 = (CCActionInterval*)(CCSequence::actions(actionTo,
CCCallFunc::actionWithTarget(this, callfunc_selector(FirstLayer::miaokaiRandom)),NULL));
plight->runAction(rep1);
5.//随机速度
int actualDuration = 1;
//Create the actions
CCFiniteTimeAction* actionMove = CCMoveTo::create(actualDuration, ccp( _player->getPosition().x, _player->getPosition().y) );//创建动作
CCFiniteTimeAction* actionMoveDone = CCCallFuncN::create( this, NULL);
_player->runAction( CCSequence::actions(actionMove, actionMoveDone, NULL) );//执行动作
6. //延迟
CCDelayTime *stay = CCDelayTime::actionWithDuration(1.2f);
CCCallFunc* callDelay = CCCallFunc::actionWithTarget(this, callfunc_selector(FeedbackLayer::stateReset));
CCFiniteTimeAction* action = CCSequence::actions(stay, callDelay, NULL);
runAction(action);
7.放大缩小倒计时
CCSprite* timeSprite = CCSprite::createWithSpriteFrameName("Number_1.png");
timeSprite->setPosition(ccp(this->getContentSize().width*0.5f, this->getContentSize().height*0.5f));
timeSprite->setTag(100);
timeSprite->setScale(0.00001f);
this->addChild(timeSprite);
CCActionInterval* getSetScaleIn = CCScaleTo::create(0.75f, 1.0f);
// 渐快的弹性移动
getSetScaleIn = CCEaseElasticOut::create(getSetScaleIn);
CCActionInterval* getSetScaleOut = CCScaleTo::create(0.5f, 3.0f);
// 渐快的移动
getSetScaleOut = CCEaseExponentialIn::create(getSetScaleOut);
CCActionInterval* getSetScaleNothing = CCScaleTo::create(0.0f, 0.0f);
CCActionInterval* getSetFadeOut = CCFadeOut::create(0.5f);
getSetFadeOut = CCEaseExponentialIn::create(getSetFadeOut);
CCActionInterval* getSetFadeIn = CCFadeIn::create(0.0f);
timeSprite->runAction(CCSequence::create(getSetScaleIn, getSetScaleOut, NULL));
timeSprite->runAction(CCSequence::create(CCDelayTime::create(0.75f), getSetFadeOut, getSetFadeIn, getSetScaleNothing, NULL));
////////////////////////////////////////////////////////////
CCSprite* timeSprite1 = CCSprite::createWithSpriteFrameName("Number_2.png");
timeSprite1->setPosition(ccp(this->getContentSize().width*0.5f, this->getContentSize().height*0.5f));
timeSprite1->setTag(101);
timeSprite1->setScale(0.00001f);
this->addChild(timeSprite1);
timeSprite1->runAction(CCSequence::create(CCDelayTime::create(1.25f), getSetScaleIn, getSetScaleOut, getSetScaleNothing, NULL));
timeSprite1->runAction(CCSequence::create(CCDelayTime::create(2.25f), getSetFadeOut, getSetFadeIn, NULL));
////////////////////////////////////////////////////////////
CCSprite* timeSprite2 = CCSprite::createWithSpriteFrameName("Number_3.png");
timeSprite2->setPosition(ccp(this->getContentSize().width*0.5f, this->getContentSize().height*0.5f));
timeSprite2->setTag(102);
timeSprite2->setScale(0.00001f);
this->addChild(timeSprite2);
CCActionInstant* callback = CCCallFunc::create(this, callfunc_selector(UILayer::performSaveMe));
timeSprite2->runAction(CCSequence::create(CCDelayTime::create(2.55f), getSetScaleIn, getSetScaleOut, getSetScaleNothing, NULL));
timeSprite2->runAction(CCSequence::create(CCDelayTime::create(3.55f), getSetFadeOut, getSetFadeIn, callback, NULL));

浙公网安备 33010602011771号