我正在尝试永久地播放帧动画序列,但是在每次播放之后,我想在下一个循环之前延迟一段时间。
以下是具体代码:
CCActionInterval *pAnimate = CCAnimate::create( m_pAnimationDebugSkill );
CCDelayTime *pDelayTime = CCDelayTime::create( 3.0f );
CCRepeatForever *pRepeat = CCRepeatForever::create( CCSequence::createWithTwoActions(pAnimate, pDelayTime) );
m_pSpriteDebugSkillAnimation->runAction( pRepeat );
我期待pAnimate播放,然后pDelayTime保持3秒,然后pAnimate再次播放... 但是发生的事情是pAnimate正在播放并永远重复...... pDelayTime根本没有效果......
任何人都有任何想法?
这是完整的代码:
// 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 );
答案 0 :(得分:0)
您可以尝试在函数中运行动画:
void MyGame::runMyAnimation()
{
CCActionInterval *pAnimate = CCAnimate::create( m_pAnimationDebugSkill );
m_pSpriteDebugSkillAnimation->runAction( pAnimate );
}
并改为运行此代码:
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)));
<强>更新强>
你的代码可能就像这样:
尝试将动画所需的时间添加到延迟时间。
答案 1 :(得分:0)
问题是您已将m_pAnimationDebugSkill的循环设置为-1。
m_pAnimationDebugSkill->setLoops( -1 );
这使得这个动画运行无限,因此延迟部分没有执行..
如果稍后使用ccrepeatforever,则不需要将循环设置为-1。
除此之外代码看起来很好