ioscocos2d-iphonespritebuilder

Play Spritebuilder animation from timeline - Cocos2d


I can't get this to work and it is driving me insane. I simply want to play my animation when it is called. I am using Spritebuilder and Cocos2d. I have a CCNode that I am importing into the scene using

#import "heroCharacter.h"
//Reference
CCNode *_heroContainer;
//Then

CCNode *hero = [CCBReader loadAsScene:@"heros/panda"];
[_heroContainer addChild:hero z:1 name:@"level1"];

That CCNode contains various timeline animations.

I am trying to call the animation using :

CCBAnimationManager* animationManager = _heroContainer.userObject;
NSLog(@"AM: %@", animationManager);
[animationManager runAnimationsForSequenceNamed:@"ouch"];

AM returns a Null value. How would I correctly reference this?

I presume it is because I am importing it and it is losing its connection but not sure how to do it correctly.


Solution

  • The Animation Manager is not on the node you want to run the animation on, but always on the root node of the CCB. I tripped over that, too. :)

    For instance if your hero is part of GameScene.ccb then you would have to get a reference to the GameScene's root node (typically a custom class) and get the animation manager from that object.

    If your hero is in another CCB (say player.ccb) that is referenced by GameScene.ccb and the timeline animation you want to play was edited in player.ccb then you would have to obtain the animation manager from the sub file node in GameScene.ccb that is referencing player.ccb. Each CCB's root node contains the animation manager that stores the timeline animations for its CCB.

    Note that v3.1 will have an animationManager property, if you are already on v3.1 (develop branch) then you'd have to use that property rather than userObject.