[英]Score label node disappears after first round
我不知道为什么,但是在第一轮之后得分标签节点消失了。我有两个分数,一个用于人类,另一个用于计算机:
-(void)scoreCount{
if(scoreLabel == nil){
NSString* scoretxt =[NSString stringWithFormat:@"0"];
[scoreLabel setText:scoretxt];
scoreLabel = [SKLabelNode labelNodeWithFontNamed:@"ROTORcapExtendedBold"];
scoreLabel.fontSize = 65.f;
scoreLabel.fontColor = [UIColor grayColor];
scoreLabel.position = CGPointMake(CGRectGetMidX(self.frame)/2,CGRectGetMaxY(self.frame)-70);
scoreLabel.zPosition = -1;
[self addChild:scoreLabel];
}
scoreLabel.text = [NSString stringWithFormat:@"%ld",(long)score];
if(scoreLabelCom == nil){
NSString* scoretxtcom =[NSString stringWithFormat:@"0"];
[scoreLabelCom setText:scoretxtcom];
scoreLabelCom = [SKLabelNode labelNodeWithFontNamed:@"ROTORcapExtendedBold"];
scoreLabelCom.fontSize = 65.f;
scoreLabelCom.fontColor = [UIColor grayColor];
scoreLabelCom.position = CGPointMake(CGRectGetMidX(self.frame)+(CGRectGetMidX(self.frame)/2),CGRectGetMaxY(self.frame)-70);
scoreLabelCom.zPosition = -1;
[self addChild:scoreLabelCom];
}
scoreLabelCom.text = [NSString stringWithFormat:@"%ld",(long)scoreCom];
}
每当有人得到一个点时,就会调用这个方法,然后我就投入了
-(void)update:(CFTimeInterval)currentTime {
[self scoreCount];
}
因为,没有它,scoreCount不会显示0分,但只会在第一点之后出现,但是,当新一轮开始时,ScoreCout根本不会出现。 我怎么纠正呢? 为什么会这样?
这个(long)score
和(long)scoreCom
你现在可以为它增加价值。
score = score + 1; //Before add to nsstring
scoreLabel.text = [NSString stringWithFormat:@"%ld",(long)score];
和
scoreCom = scoreCom + 1;//Before add to nsstring
scoreLabelCom.text = [NSString stringWithFormat:@"%ld",(long)scoreCom];
好了,我不知道它有多好,但我想补充scoreLabel = nil
和scoreLabelCom = nil
在didBeginContact
当比赛结束,现在的工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.