0

I am trying to play a frame animation sequence looping forever, but after each play, I'd like to delay for a period of time before the next loop.

Here's the specific code:

    CCActionInterval *pAnimate = CCAnimate::create( m_pAnimationDebugSkill );
    CCDelayTime *pDelayTime = CCDelayTime::create( 3.0f );
    CCRepeatForever *pRepeat = CCRepeatForever::create( CCSequence::createWithTwoActions(pAnimate, pDelayTime) );
    m_pSpriteDebugSkillAnimation->runAction( pRepeat );

I am expecting pAnimate to play, then pDelayTime to hold for 3 seconds, then pAnimate to play again... But what happens is pAnimate is playing and repeating forever... pDelayTime has no effect at all...

Anyone has any idea?

Here's the complete code:

        // Skill button animation
    m_pSpriteDebugSkillAnimation = CCSprite::createWithSpriteFrame(
        CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName(s_szNameSpriteFrame[UI_BOARD_RUNES_ANIM_BTN_SKILL_0])
    );
    m_pSpriteDebugSkillAnimation->setAnchorPoint(ccp(0.5f, 0.5f));
    INT iNumFrames = UI_BOARD_RUNES_ANIM_BTN_SKILL_END - UI_BOARD_RUNES_ANIM_BTN_SKILL_START + 1;
    CCArray *pAnimSkill = CCArray::create();
    for ( INT i = 0; i < iNumFrames; i++ ) {
        CCSpriteFrame *pFrame = CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName(s_szNameSpriteFrame[UI_BOARD_RUNES_ANIM_BTN_SKILL_0+i]);
        pAnimSkill->addObject(pFrame);
    }
    m_pAnimationDebugSkill = CCAnimation::createWithSpriteFrames( pAnimSkill, DEFAULT_TIME_ANIM );
    m_pAnimationDebugSkill->setLoops( -1 );
    m_pAnimationDebugSkill->retain();
    CCActionInterval *pAnimate = CCAnimate::create( m_pAnimationDebugSkill );
    CCDelayTime *pDelayTime = CCDelayTime::create( 3.0f );
    CCRepeatForever *pRepeat = CCRepeatForever::create( CCSequence::createWithTwoActions(pAnimate, pDelayTime) );
    m_pSpriteDebugSkillAnimation->runAction( pRepeat );

    CCSprite *pSpriteSkill = CCSprite::createWithSpriteFrame(
        CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName(s_szNameSpriteFrame[UI_BOARD_RUNES_BTN_SKILL])
    );
    FLOAT fSpriteSkillWidth = pSpriteSkill->boundingBox().size.width;
    FLOAT fSpriteSkillHeight = pSpriteSkill->boundingBox().size.height;
    m_pSpriteDebugSkillAnimation->setPosition(ccp(fSpriteSkillWidth/2.0f, fSpriteSkillHeight/2.0f));
    pSpriteSkill->addChild( m_pSpriteDebugSkillAnimation );
    //pSpriteSkill->setAnchorPoint(ccp(0.5f, 0.5f));
    //pSpriteSkill->setPosition(ccp(fScreenHalfWidth, 1100.0f));
    //this->addChild(pSpriteSkill);
    m_pBtnDebugSkill = CCMenuItemSprite::create( pSpriteSkill, pSpriteSkill, pSpriteSkill, this, menu_selector(CGameScreen::onTouchSkillButton) );
    m_pBtnDebugSkill->setPosition(ccp(fScreenHalfWidth, 1100.0f));
    m_pMenuRoot->addChild( m_pBtnDebugSkill );
Zennichimaro
  • 5,236
  • 6
  • 54
  • 78

2 Answers2

0

You could try running the animation in a function:

void MyGame::runMyAnimation()
{
    CCActionInterval *pAnimate = CCAnimate::create( m_pAnimationDebugSkill );
    m_pSpriteDebugSkillAnimation->runAction( pAnimate );
}

and run this code instead:

CCDelayTime *pDelayTime = CCDelayTime::create( 3.0f /* add the time the animation takes here*/);
CCRepeatForever *pRepeat = CCRepeatForever::create( CCSequence::createWithTwoActions(pDelayTime, CCCallFunc::create(this,callfunc_selector(MyGame::runMyAnimation)));

UPDATE

Probably your code works like this:

  1. Start animation
  2. wait for 3 seconds (while the animation is running)
  3. Start animation again

Try adding the time your animation takes to the delay time.

Daniel
  • 20,420
  • 10
  • 92
  • 149
0

the problem is that you have set loops for m_pAnimationDebugSkill to -1.

    m_pAnimationDebugSkill->setLoops( -1 );

this is making this animation run for infinite and therefore the delay part is not executing ..

you don't need to set loops to -1 if you are later using ccrepeatforever.

other then that the code looks fine

Jain
  • 854
  • 5
  • 15