简体   繁体   English

更新分数标签

[英]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? 例如,初始值为0,新值为10,数字10与0重叠,而不是用10代替0。有人可以帮忙吗?

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 当您要更新它时,只需要调用setText

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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