繁体   English   中英

分数标签节点在第一轮后消失

[英]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 = nilscoreLabelCom = nildidBeginContact当比赛结束,现在的工作。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM