Problem playing repeat animation/action?
- by Beast
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);
}