分数标签显示值覆盖

时间:2016-01-22 21:45:27

标签: ios objective-c sprite-kit nsstring

当分数更新时,新的分数值标签会覆盖显示屏上的旧分数,因为这个分数是不可读的,如何更新新分数?我在这里得到了什么:

SKLabelNode *ScoreLabel;
NSInteger score = 0;
-----------------------------
-(void)Scoring{
score = score +1;
ScoreLabel = [SKLabelNode labelNodeWithFontNamed:@"Arial"];
ScoreLabel.position = CGPointMake(CGRectGetMidX(self.frame), 960);
ScoreLabel.text = [NSString stringWithFormat:@"%ld",(long)score];
[self addChild:ScoreLabel];
}

1 个答案:

答案 0 :(得分:3)

每次分数更改顶部的新标签时,您都会添加。像这样更改代码:

-(void)Scoring{
  score = score +1;
  if (ScoreLabel == nil) {
    ScoreLabel = [SKLabelNode labelNodeWithFontNamed:@"Arial"];
    ScoreLabel.position = CGPointMake(CGRectGetMidX(self.frame), 960);
    [self addChild:ScoreLabel];
  }
  ScoreLabel.text = [NSString stringWithFormat:@"%ld",(long)score];

}