score label display value overwrites

筅森魡賤 提交于 2019-12-13 04:00:50

问题


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

回答1:


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

}


来源:https://stackoverflow.com/questions/34956475/score-label-display-value-overwrites

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!