In my app I have a great number of different animations of my sprite, and there will be more of tham in later versions. It is quite difficult to use texture file will hundreds of frames, so I whould like to make several of tham. So, I wrote this code:
if (running)
{
NSArray * animations = [[physicalBody getAnimationList] objectForKey:ANIMATION_RUN];
if (!inAir)
{
currentFrame++;
if (currentFrame>=[animations count]*ANIMATION_ITERATION)
currentFrame = 0;
}
else
{
currentFrame = 2;
}
PhysicsSprite *sprite = (PhysicsSprite*)[physicalBody getSprite];
[sprite setFlipX:(moveingDirection)];
[sprite setDisplayFrame:[animations objectAtIndex:currentFrame/ANIMATION_ITERATION]];
}
else
{
NSArray * animations = [[physicalBody getAnimationList] objectForKey:ANIMATION_STAND];
currentFrame++;
if (currentFrame>=[animations count]*ANIMATION_ITERATION)
currentFrame = 0;
PhysicsSprite *sprite = (PhysicsSprite*)[physicalBody getSprite];
[sprite setFlipX:(moveingDirection)];
[sprite setDisplayFrame:[animations objectAtIndex:currentFrame/ANIMATION_ITERATION]]; //error here
}
Array of animations was created from different *.png, and when it tries to switch tham, i got this error:
* Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'CCSprite: setTexture doesn't work when the sprite is rendered using a CCSpriteBatchNode'
How can I switch texture files? Or may be there is another solution?