1

I don't know why, but score label node dissapears after first round.I have two scores, one for human ,other for computer :

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

this method is called every time somebody is getting a point, and I put in

-(void)update:(CFTimeInterval)currentTime {
 [self scoreCount];
 }

because, without it scoreCount wont show 0 points, but only show up after first point, but, when new round starts, ScoreCout wont show up at all. how can I correct it? And why it is happening?

artG
  • 235
  • 3
  • 12
  • *this method is called every time somebody is getting a point* - That is not true. It is called 60 times per second because you run it inside of an `update:` method. It would be better if you really change label's text only when score is increased. I mean, it probably not hurt your app's performance, but it is not necessary. – Whirlwind May 03 '16 at 18:20
  • And when I say *it probably not affect on your app's performance* it doesn't mean that you should't fix. Doing non-performant stuff like that may eventually affect on your app's performance. See this example about how you can implement it in a performant way : http://stackoverflow.com/a/34841022/3402095 – Whirlwind May 03 '16 at 18:32
  • ok, will do that, but first, Iam still trying to figure it out how to fix the problem what I sad in post – artG May 03 '16 at 18:57

2 Answers2

1

This (long)score and (long)scoreCom You can add value to it by now.

score = score + 1; //Before add to nsstring
scoreLabel.text = [NSString stringWithFormat:@"%ld",(long)score];

And

scoreCom = scoreCom + 1;//Before add to nsstring
scoreLabelCom.text = [NSString stringWithFormat:@"%ld",(long)scoreCom];

beerwin
  • 9,813
  • 6
  • 42
  • 57
0

Well, I don't know how good it is but I add scoreLabel = nil and scoreLabelCom = nil at didBeginContactwhen game ends, and it works now.

artG
  • 235
  • 3
  • 12