![](/img/trans.png)
[英]How to display a score label in a swift Sprite Kit game with Singleton
[英]score label display value overwrites
当THE乐谱更新时,新的乐谱值标签会覆盖显示屏上的旧乐谱,因为该乐谱只是不可读,如何更新新乐谱? 这是我得到的:
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];
}
每当分数更改顶部时,您都将添加一个新标签。 像这样更改代码:
-(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];
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.