0

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];
}
Stefan
  • 5,203
  • 8
  • 27
  • 51
artG
  • 235
  • 3
  • 12

1 Answers1

3

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

}
Stefan
  • 5,203
  • 8
  • 27
  • 51
  • the check should probably be `ScoreLabel == nil` or simply `!ScoreLabel`. And you might as well hint that variables and methods should start with a lower case letter, as the syntax highlighting is already getting confused here. – luk2302 Jan 22 '16 at 21:53
  • Thank you, i try to fix this problem for days – artG Jan 22 '16 at 22:04