Search code examples
xcodeanimationccspritespritebuilder

Multiple animations with one CCSprite from Spritebuilder


I was wondering if it is possible to have multiple animations with 1 single CCSprite and trigger them individually.

My current solution is to have two animations on the timeline of the CCSprite. What I have done is: For example my CCSprite can walk and jump, I have set the walk animation from 0 seconds to 0.8 seconds. The jump animation starts on 1 second to 1.8 seconds and the total time of the timeline is 2 seconds.

If I want to trigger the second animation I can perform the following action:

[CCSpriteObject.animationManager jumpToSequenceNamed:@"Timeline" time:1];
[CCSpriteObject.animationManager runAnimationsForSequenceNamed:@"Timeline"];

This way it only shows the animation from 1 second to further on the timeline and I have the possibility to show only the second animation.

Is there also a way to single out the first animation, from 0 to 1 seconds? (Because if I just call runAnimationsForSequence... the total 2 seconds will run and shows both animations!)

Or should I setup the two animations in a different manner?

@Edit I have read that it is also possible to have two different CCSprites and make the one visible which animation is being triggered. However I would like to see a solution which has two animations on just 1 CCSprite!


Solution

  • I discovered that it is possible to have two seperate timelines on the same CCSprite, probably this is basic knowledge of spritebuilder. But since this is not easily to be found on the web, I will keep this post and not delete it. (For if anyone also has the same question)