我希望以下代码将标签放在屏幕的右上角。但是,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
无效。
答案 0 :(得分: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);