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
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:
Then in your init method to set the
_scoreto0:Then increment (add 1 to) your
_scorevariable and set the string (the text content) of your_scoreLabelto that value.The line
[_scoreLabel setString:[NSString stringWithFormat:@"%d", _score]];is a way to convert the integer of_scoreto a string (NSString). It’s an old C way of doing it, the%dmeans 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):