CCLabelTTF always positions the labels in the wrong place

Forums Programming cocos2d support (graphics engine) CCLabelTTF always positions the labels in the wrong place

This topic contains 3 replies, has 2 voices, and was last updated by  zardon 2 years, 2 months ago.

Viewing 4 posts - 1 through 4 (of 4 total)
Author Posts
Author Posts
February 7, 2012 at 6:31 am #239024


Hello there.

I have created a label with left alignment and I want the label to start a certain position (x,y) as below;

CCLabelTTF *lblHeader = [CCLabelTTF labelWithString:@"New game" dimensions:CGSizeMake(250, 25) alignment:UITextAlignmentLeft lineBreakMode:UILineBreakModeClip fontName:@"Georgia" fontSize:18];

[lblHeader setPosition:CGPointMake(105, 275)];

[self addChild:lblHeader];

But if I change the contents of the label to:

New game > Color scheme

The position of the label is now in a different place, and it seems to put things based off the center, even though the alignment is left.

How do I force a label (regardless of whether its bitmap or not) to start at the position specified?

I tried anchor points;

[lblHeader setAnchorPoint:CGPointMake(0.5, 0.5)];

[lblHeader setIsRelativeAnchorPoint:YES];

But this seems to make no difference.

I also changed the dimensions to dimensions:CGSizeMake(100, 25)

Which seems to solve the problem, but I don’t understand why making the dimensions wider would suddenly start positioning things further left.

What I’d like to know, therefore, is how:

1. Make a label start at position x,y but have dimensions that strictly start at position x,y.


February 7, 2012 at 8:06 am #364853


You have the anchorPoint set in the middle, so it scales from the middle. Try setting it to ccp(0,0.5) instead :)

(For a label that is always anchored to the right, you’d set it to ccp(1,0.5) of course)

February 7, 2012 at 4:35 pm #364854


Hello @Scryb. I will try your idea and see if it makes any difference. I want to try it with short words and long words. Hopefully it should not matter and all the labels should start at the position I set in x,y

I will post an update later on

February 8, 2012 at 4:03 am #364855


This is great – it works fine. Thanks again

Viewing 4 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic.