2016-01-22 25 views
0

当分数更新时,新的分数值标签会覆盖显示屏上的旧分数值,因为此分数只是无法读取,所以如何更新新分数?这里我得到了什么:分数标签显示值覆盖

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

回答

3

你每增加一个新的标签在顶部添加分数。更改代码是这样的:

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

} 
+0

检查应该可能是'ScoreLabel == nil'或者干脆就是'!ScoreLabel'。你也可以提示变量和方法应该以小写字母开头,因为语法突出显示在这里已经变得混乱了。 – luk2302

+0

你说得对,我已经更新了我的答案。谢谢 – Stefan

+0

谢谢,我试着解决这个问题好几天 – artG