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 1 year, 10 months ago.
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)];
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)];
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.
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)
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
This is great – it works fine. Thanks again
You must be logged in to reply to this topic.
Social Widgets powered by AB-WebLog.com.