Problem playing repeat animation/action?
Posted
by
Beast
on Game Development
See other posts from Game Development
or by Beast
Published on 2012-06-07T10:40:12Z
Indexed on
2012/06/07
10:48 UTC
Read the original article
Hit count: 201
I'm calling this function on multiple sprites after checking numberOfRunningActions()"to play same animation but it's not working only the first tagged sprite plays the animation. What am I doing wrong?
void CGame::playAnimation(const char* filename, int tag, CCLayer* target)
{
CCAnimation* animation = CCAnimation::animation();
CCSprite* spriteSheet = CCSprite::spriteWithFile(filename);
for(int i = 0; i < spriteSheet->getTexture()->getPixelsWide()/SIZE; i++) // SIZE is an int value
{
animation->addFrameWithTexture(spriteSheet->getTexture(), CCRect(SIZE * i, 0, SIZE, SIZE));
}
CCActionInterval* action = CCAnimate::actionWithDuration(1, animation, true);
CCRepeatForever* repeatAction = CCRepeatForever::actionWithAction(action);
target->getChildByTag(tag)->runAction(repeatAction);
}
© Game Development or respective owner