简体   繁体   中英

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM