【问题标题】:score label display value overwrites分数标签显示值覆盖
【发布时间】:2016-01-22 21:45:26
【问题描述】:

当分数更新时,一个新的分数值标签会覆盖显示屏上的旧分数,因为这个分数是不可读的,如何更新新分数?这是我得到的:

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

【问题讨论】:

    标签: ios objective-c sprite-kit nsstring


    【解决方案1】:

    每次分数更改顶部的新标签时,您都会添加。像这样更改代码:

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

    【讨论】:

    • 支票应该是ScoreLabel == nil 或简单的!ScoreLabel。你也可以暗示变量和方法应该以小写字母开头,因为这里的语法高亮已经很混乱了。
    • 谢谢,我尝试解决这个问题好几天
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-01-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多