1

This is driving me insane. I am trying to access the CCB root node so I can get the animation timeline using SpriteBuilder/Cocos2d.

I have heroCharacter.m that is the custom class of my animation CCNode.

I am importing it into bedroomScene.m. using

CCNode *_heroContainer;

and in my view did load

//Import Hero Scene
    CCNode *hero = [CCBReader loadAsScene:@"heros/panda"];
    [_heroContainer addChild:hero];

When I run animationManager it is a null value.

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

Any suggestions?

memyselfandmyiphone
  • 1,080
  • 4
  • 21
  • 43

1 Answers1

3

First of all, when you add a CCB as child of another node you should use load: not loadAsScene:

CCNode *hero = [CCBReader load:@"heros/panda"];
[_heroContainer addChild:hero];

With the above code hero will be the root node of the heros/panda CCB file.

With your code using loadAsScene the root node is wrapped in a CCScene object and therefore hero points to the CCScene instance, not the CCB's root node. The CCScene's children array only contains one child node which would be the actual CCB root node.

Next you're adding the loaded CCB as child of _heroContainer. However the animation manager for a given CCB is always on the CCB's root node, which means (if you used load: not loadAsScene:) the animation manager is in the hero object, it can't be in the _heroContainer node:

CCBAnimationManager* animationManager = hero.userObject;
NSLog(@"AM: %@", animationManager);

Note that if you upgrade to v3.1 of cocos2d you can simply use hero.animationManager to access the CCBAnimationManager.

CodeSmile
  • 64,284
  • 20
  • 132
  • 217