0
votes

I would expect the following code to position the label at the upper right of the screen. However the x position appears off to the right of the screen and I have to manually move it way over. What is wrong with this code?

CGSize winSize = [[CCDirector sharedDirector] winSize];

self.screenTop = winSize.height;
self.screenRight = winSize.width;
self.screenBottom = 0;
self.screenLeft = 0;


self.scoreLabel = [CCLabelTTF labelWithString:@"000000" dimensions:CGSizeMake(200,30) hAlignment:kCCTextAlignmentRight fontName:@"Helvetica" fontSize:24];
self.scoreLabel.position = ccp(self.screenRight - 20, self.screenTop - 20);
[self addChild:self.scoreLabel z:1];

The position is logged correctly as {548, 300} (iPhone5). It appears that hAlignment:kCCTextAlignmentRight doesn't work right.

1
horizontalAlignment is the alignment of the text in its bounding box. It's only useful if you have multiline text.Stephane Delcroix

1 Answers

0
votes
self.scoreLabel.position = ccp(self.screenRight - 100, self.screenTop - 20);

more generically :

self.scoreLabel.position = ccp(self.screenRight - self.scoreLabel.contenSize.width/2,
self.screenTop - self.scoreLabel.contenSize.height/2);