Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to add a CCLabel to a CCSprite in a CCSpriteBatchNode?

I have a CCSpriteBatchNode that is added to my Scene.

I have a CCSprite that is created with "initWithSpriteFrameName," then I add it to my batch node.

The sprite displays correctly. However, after that I add a CCLabelTTF as a child to the CCSprite, and the app crashes with the following error:

"CCSprite is not using the same texture id"

Is there any way to add the Label as a child node of the sprite?

like image 457
TigerCoding Avatar asked Dec 10 '25 19:12

TigerCoding


1 Answers

You can add the label only if you don't add the CCSprite to a CCSpriteBatchNode. CCSpriteBatchNode only allows CCSprite as children, and that also extends to children of children.

If that's not an option, simply add the label to the scene hierarchy elsewhere and then update the position of the label to the sprite's position using an update method, in order to synchronize the label's and sprite's positions.

like image 110
LearnCocos2D Avatar answered Dec 13 '25 08:12

LearnCocos2D