0

我希望以下代码将标签定位在屏幕的右上角。但是 x 位置出现在屏幕右侧,我必须手动将其移过。这段代码有什么问题?

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];

该位置正确记录为 {548, 300} (iPhone5)。看来这hAlignment:kCCTextAlignmentRight行不通。

4

1 回答 1

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

更一般地说:

self.scoreLabel.position = ccp(self.screenRight - self.scoreLabel.contenSize.width/2,
self.screenTop - self.scoreLabel.contenSize.height/2);
于 2013-03-12T01:38:27.827 回答