我不知道为什么,但是在第一轮之后得分标签节点消失了。我有两个分数,一个用于人类,另一个用于计算机:
-(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根本不显示。 我该如何纠正?为什么会这样?
答案 0 :(得分:0)
这(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];
答案 1 :(得分:0)
好吧,我不知道它有多好,但是当游戏结束时我在scoreLabel = nil
添加了scoreLabelCom = nil
和didBeginContact
,现在就可以了。