Best way to display a game score on iPhone with cocos2d?

I am looking to persistently display a game score in an iPhone app using cocos2d. Going off the code that cocos2d shows the FPS the app is running at:

-(void) showFPS
    accumDt += dt;

    if ( accumDt > 0.1)  {
        frameRate = frames/accumDt;
        frames = 0;
        accumDt = 0;

    NSString *str = [NSString stringWithFormat:@"%.1f",frameRate];
    [FPSLabel setString:str];
    [FPSLabel draw];

I can get the score to display properly, but it flickers, even though the app is running at faster that 60 FPS... Any ideas?


Try using LabelAtlas instead. It is faster (it consumes much less CPU). See the AtlasDemo that comes with the cocos2d distribution to see how to use it.

For anyone who might be interested, I ended up using a cocos2d Label as so:

scoreLabel = [Label labelWithString: [NSString stringWithFormat:@"%d", score] dimensions: CGSizeMake(180, 20) alignment: UITextAlignmentRight fontName:@"Arial" fontSize: 20];
[scoreLabel setPosition: cpv(100,100)];
[self add: scoreLabel];

Hopefully this can help someone else.

Need Your Help

jQuery: Wait till multiple GET requests are successully processed

jquery wait get-request

I need to issue multiple $.get requests, process their responses, and record the results of the processing in the same array. The code looks like this:

how to set gaps between lines


I need to set space for each line <br> tag is taking huge.