user339946
user339946

Reputation: 6119

Adding a CCLabel ontop of an animated CCSprite

I seem to be having trouble adding a CCLabelTTF on top of an animated CCSprite. I am basically trying to add it to my sprite by using [self.sprite addChild:label]. This crashes with an error:

Terminating app due to uncaught exception 'NSInternalInconsistencyException', 
reason: 'CCSprite is not using the same texture id'

How can I simply put a label on top of my sprite? Thanks

Upvotes: 0

Views: 234

Answers (2)

SentineL
SentineL

Reputation: 4732

I'm not shure what exacely going wrong in your code, but You may try to add your CCSprite to CCNode, and then, add CCLabelTTF to this node. Than, you may run any frame-changing animation on your sprite, and any rotate/move etc animations on this node: sprite and label will move sinchronizely.

Upvotes: 1

YvesLeBorg
YvesLeBorg

Reputation: 9079

Your animation is probably a CCSpriteBatchNode, you cant add a sprite to a CCSpriteBatchNode child or to a CCSpriteBatchNode if the sprite does not have the same texture. You canot either add self.sprite to a node (since it is already a child of the batchNode). I guess that leaves you with

  1. creating the animated sprite without a batchNode, or
  2. Creating a CCNode to which you add first the CCSpriteBatchNode and later the label.

Upvotes: 1

Related Questions