user3500701
user3500701

Reputation: 11

Update Score Label

need help here. I am trying to update the score with the code below but instead of displaying a new score, the label text name was overlap each other. For example, initial value is 0 and new value is 10, instead of replacing 0 with 10, the number 10 was overlap with 0. Anyone can help?

Code:

self.sumLabel = [SKLabelNode labelNodeWithFontNamed:@"Chalkduster"];
self.sumLabel.text = @"Score: 0";
self.sumLabel.fontSize = 20;
self.sumLabel.position = CGPointMake(self.size.width-160, self.size.height-450);
[self.sumLabel setText:[NSString stringWithFormat:@"Score: %i", self.initial]];
[self addChild:self.sumLabel];

Upvotes: 0

Views: 77

Answers (1)

Antzi
Antzi

Reputation: 13424

It looks like you are creating and adding a label multiple times. Try to reuse the previous one by storing the object into a property

When you want to update it, you just need to call setText

Upvotes: 1

Related Questions