views:

26

answers:

2

How can I add text or characters into a Sprite. If it's not possible, is there any alternative to get the same effect?

NOTE: I am using COCOS2D framework.

EDIT:

I have tried in this way-

CCLabel* label = [[CCLabel alloc] initWithString:@"H!" dimensions:CGSizeMake([spriteObj contentSize].width, [spriteObj contentSize].height)  alignment:UITextAlignmentCenter fontName:@"verdana" fontSize:15.0f];
//label.position = newBubble.position;//ccp([spriteObj contentSize].width/2, [spriteObj contentSize].height/2);
[spriteObj addChild:label z: 10];

It shows the text 'H!' at the bottom left corner of the sprite.

A: 

Just create the CCLabel like you are doing and set its position to the desired location by calling:[label setPosition:spriteObj.position]; That will move the label to the position of the sprite.

If your sprite is moving and you want the label to move along with it, place that line in your update method.

pabloruiz55
A: 

I have done it using addChild method of Sprite. The position is set with respect to the left bottom co-ordinate of that Sprite.

Note: I have used cocos2d.

Sadat