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 8380157
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T16:22:59+00:00 2026-06-09T16:22:59+00:00

Possible Duplicate: Scoring System In Cocos2D I got a reply from a question I

  • 0

Possible Duplicate:
Scoring System In Cocos2D

I got a reply from a question I asked earlier but I am new to coding and have no idea how to do it. Here is the reply:

"@synthesize a "score" property of type int, and a "scoreLabel" property of type CCLabelTTF.

initialize your score property to "0" in -(void)init

On line 126, increment your "score" property by 1, and set that value into your CCLabelTTF."

Can you tell me how to do this? plz. link to my other post

—– Scoring System In Cocos2D

  • 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-06-09T16:23:00+00:00Added an answer on June 9, 2026 at 4:23 pm

    When you synthesize a private variable (other classes cannot see it) you allow a way for other classes to see and/or modify the value of that variable.

    First, you want to create the variable:

    NSMutableArray *_targets;
    NSMutableArray *_projectiles;
    
    int _score;
    CCLabelTTF *_scoreLabel;
    

    Then in your init method to set the _score to 0:

    -(id) init
    {
        if( (self=[super init] )) {
            [self schedule:@selector(update:)];
            _score = 0;
    

    Then increment (add 1 to) your _score variable and set the string (the text content) of your _scoreLabel to that value.

            if (CGRectIntersectsRect(projectileRect, targetRect)) {
                [targetsToDelete addObject:target];     
                _score++;
                [_scoreLabel setString:[NSString stringWithFormat:@"%d", _score]];                    
            }   
    

    The line [_scoreLabel setString:[NSString stringWithFormat:@"%d", _score]]; is a way to convert the integer of _score to a string (NSString). It’s an old C way of doing it, the %d means that whatever is going to be there should be displayed as an integer as opposed to a float (having decimal points).

    It also looks like you need to “instantiate” your label and add it as a child to the layer. Instantiation is just a fancy term for creating a instance of something. Think of a “class” as a blueprint for a chair, and an “instance” as a chair created from that blueprint. Once you have the chair created (an instance), you can modify it (paint it, add/remove legs, etc).

    So, to instantiate your label and add it to the layer (itself):

    -(id) init
    {
        if( (self=[super init] )) {
            [self schedule:@selector(update:)];
            _score = 0;
    
            //Create label
            _scoreLabel = [CCLabelTTF labelWithString:@"0" fontName:@"Marker Felt" fontSize:16];
    
            //Add it to a layer (itself)
            [self addChild:_scoreLabel];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Child Scope & CS0136 C# Variable Scoping Though I have been using
Possible Duplicate: regex for URL including query string I have a text or message.
Possible Duplicate: Python nested functions variable scoping After much trial and error I have
Possible Duplicate: Mongo interface I am new to mongo db, and i am looking
Possible Duplicate: Add 1 hour to datetime datatype I have a timestamp stored in
Possible Duplicate: Storing echoed strings in a variable in PHP Suppose I have <?php
Possible Duplicate: Can't pass mysqli connection in session in php Many of us have
Possible Duplicate: PHP storing password in cookie In a login system, if a user
Possible Duplicate: Given a 2d array sorted in increasing order from left to right
Possible Duplicate: Secure hash and salt for PHP passwords THREE part question: Which technique

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.