artG
artG

Reputation: 235

score label display value overwrites

When THE score updates, a new score value label overwrites old one on the display, because of this score is just unreadable, how to update new score? here what i got:

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

Upvotes: 0

Views: 86

Answers (1)

Stefan
Stefan

Reputation: 5461

You are adding every time the score changes a new label on top. Change the code like this:

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

}

Upvotes: 3

Related Questions