Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6669369
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T03:08:30+00:00 2026-05-26T03:08:30+00:00

so i am trying to update the score in my game, and the code

  • 0

so i am trying to update the score in my game, and the code is running fine but the structure doesnt seem right to me. what I am doing right now is keeping the score in a var and then removing the old child and adding a new child to update the score, something like :

if([self awake]){
    int score = (int) x;
    //NSLog(@"%i", score);

    CCLabelBMFont * scoreLabel = [CCLabelBMFont labelWithString:[NSString stringWithFormat:@"Score : %d", score] fntFile:@"good_dog_plain_32.fnt"];
    scoreLabel.position = ccp(100, 300);
    [scoreScene addChild:scoreLabel];

        if([_game getChildByTag:123]){
            [_game removeChildByTag:123 cleanup:YES];
        }
    [_game addChild:scoreScene z:99 tag:123];
}

now this code works just fine but its ruining the fps for the game!!! is there anyway I can update the value of scoreLabel without having to remove and then add the score to the main scene of the game?

thanks

UPDATED CODE
final fixed code :

in the main layer of the game I added

CCLabelBMFont * scoreLabel;

in the header file.

in the main init of the game I added

int score = 0;
        scoreLabel = [CCLabelBMFont labelWithString:[NSString stringWithFormat:@"Score : %d", score] fntFile:@"good_dog_plain_32.fnt"];

        CCScene * scoreScene = [CCScene node];
        scoreLabel.position = ccp(100, 300);
        [scoreScene addChild:scoreLabel];
        [self addChild:scoreScene z:99 tag:123];

and then simply used setString in my method to update the score like :

 [_game.scoreLabel setString:[NSString stringWithFormat:@"Score : %d", score]];

note that _game is because I declared the scoreLabel in the main scene, and my method is running in another file, so if you have your highscore method in the same file, there is no need for _game

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T03:08:30+00:00Added an answer on May 26, 2026 at 3:08 am

    The CCLabelBMFont implement the CCLabelProtocol, so it’s respond to the setString: method.

    You just have to had your “scoreLabel” in the init method and then update the score like that:

    if([self awake])
    {
        int score = (int) x;
        //NSLog(@"%i", score);
    
        [scoreLabel setString:[NSString stringWithFormat:@"Score : %d", score]];
    }
    

    EDIT

    It can looks like that:

    - (id)init
    {
       if ((self = [super init]))
       {
          self.score = 0;
    
          CCLabelBMFont *scoreLabel = [CCLabelBMFont labelWithString:[NSString stringWithFormat:@"Score : %d", score] fntFile:@"good_dog_plain_32.fnt"];
          scoreLabel.position = ccp(100, 300);
          [self addChild:scoreLabel z:1 tag:123];
       }
    }
    
    - (void)updateScore
    {
       CCLabelBMFont *scorelabel = (CCLabelBMFont *)[self getChildByTag:123];
       [scorelabel setString:[NSString stringWithFormat:@"Score: %d",self.score]];
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to set the score in a game but it isn't doing
I trying to update a model on a callback but the validation is causing
I'm trying to update a hashtable in a loop but getting an error: System.InvalidOperationException:
I'm trying to manually update a db in Spree, but it has no model
I simply am trying to update local storage but inside the Ext.Ajax.request I cant
I was recently trying to update my game to store graphics in compressed formats
I am trying to create a cool score counter in my iPhone game, where
TABLES: student(name,points) playsin(name->student(name), score) I'm trying to use: UPDATE STUDENT SET points = points
Basically I am trying to execute this query UPDATE communication_relevance SET score = (SELECT
I'm trying to learn some javascript and have gotten stuck. Right now, I have

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.