I have a simple CCLayer
subclass with a circle as the background image. I also have a CCLabelTTF
as a child node. How can I center the label's text on the background image?
Here's what I have:
// in MyCCLayer's init method
CCSprite *backgroundImage = [CCSprite spriteWithFile:@"circle.png"];
[self addChild:backgroundImage];
self.contentSize = backgroundImage.contentSize;
CCLabelTTF *label = [CCLabelTTF labelWithString:@"0"
dimensions:self.contentSize
alignment:UITextAlignmentCenter
fontName:@"Arial"
fontSize:32];
[self addChild:label];
I've tried changing the anchorPoint and position on the label but I can't get the text to just be centered on the background image. The text is always offset. I'd like to have centered text regardless of the font size.