문제

I'm developing something for iOS with cocos2d. Now I have this CCLabelBMFont instance variable named scoreLabel.

        scoreLabel = [CCLabelBMFont labelWithString:@"0" fntFile:@"bitmapfont.fnt"];
        scoreLabel.position = CGPointMake(screenSize.width / 2, screenSize.height / 2);
        scoreLabel.anchorPoint = CGPointMake(0.5f, 1.0f);
        [self addChild:scoreLabel z:-1];

so far, so good. It works, but now I would like to update the label with another text containing the score.

    score = currentTime;
    [scoreLabel setString:[NSString stringWithFormat:@"%i", score]];

and this doesn't work. I set a breakpoint and score contains a value, but it just won't update the label. When I replace [NSString stringWithFormat:@"%i", score] with something like @"34234" it DOES work. So i'm quite confused.

도움이 되었습니까?

해결책

Oh, finally got it. I made a stupid mistake, the score value I was trying to convert was a float. So when I tried to cast it to a string with the %i, %d or %@ format the value was lost.

thanks for the reply anyway.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top