CocosBuilder icon indicating copy to clipboard operation
CocosBuilder copied to clipboard

runAnimationsForSequenceNamed not working on CCNodes created at runtime

Open matthijn opened this issue 11 years ago • 0 comments

Currently I am working on a game with a scene, which has a board of tiles with letters. The tiles are being placed at runtime due to their positioning and 'letter value' on a dynamically generated board.

CCScene (fullscreen)
  CCLayer (board)
    CCNodes (tiles)

I have made a ccb file called Tile.ccb. This is a small & simple CCNode with a background gradient and a TTF layer. The CCNode has a timeline called 'Touched', which contains a short animation that should play when the user touches the tile. The node also has a custom class set. (STTile)

Currently I am loading every tile programatically through this method:

+ (STTile *)tileWithLetter:(NSString *)letter onRow:(int) x andCol: (int) y;
{
    STTile *tile = (STTile *)[CCBReader nodeGraphFromFile:@"Tile.ccbi"];
    tile.letterLabel.string = letter;
    tile.x = x;
    tile.y = y;
    return tile;
}

Which creates and returns a new tile for a position on the board. In Cocos2D (Objective-C), STTile is a subclass of CCNode.

The tile displays and the letterLabel can be adjusted just fine. However, playing the animation 'Touched' does not work. The following code is part of STTile and is used to play the animation/sequence upon touching:

CCBAnimationManager *animationManager = self.userObject;
[animationManager runAnimationsForSequenceNamed:@"Touched"];

The 'self.userObject' value (which holds the CCAnimationManager) is NULL, because it gets 'cleaned up' by [CCBReader nodeGraphFromFile], right after loading. Is this by design? If so, why? The same code for animating works just fine when the tile nodes have been placed in the 'board' layer at 'design time', as seen in the CocosDragon examples. (CCBFile reference in a CCB)

How is one supposed to create multiple instances of a CCB node at runtime, and still be able to run animations on them? Placing the nodes at design time is not always an option. Thanks in advance!

matthijn avatar Jul 28 '13 20:07 matthijn