runAnimationsForSequenceNamed not working on CCNodes created at runtime

565 Views Asked by At

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 dynamic 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!

1

There are 1 best solutions below

0
On

@Matthijn is right! Thanks!

In my case, it caused by inconsistent Class Name between the name of Custom Class in CocosBuilder and my codes:

Note that the name of Custom Class