This is my first post here after a couple of hours of playing with cocos2d.
I'm a web developer and I mainly work with python and php and as2 so I know object but some of the concepts that I'm encountering here are hard for me to grasp, so please be kind and patient. Then thing I can't figure out is how to modify labels, I want to add a score after the user tuch the screen, I'm using to create the label:
[code]
Label* label = [Label labelWithString:@"Score" fontName:@"Marker Felt" fontSize:64];
label.position = ccp(240, 160);
[self addChild: label z:0 tag:tagScore];
[/code]
Inside a layer dedicated only for the score label.
Then I have this in another layer:
[code]
- (BOOL)ccTouchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch* touch = [touches anyObject];
if( touch ) {
CocosNode *label = [self getChildByTag:tagScore];
[label setString:"i changed!"];
return kEventHandled;
}
}
[/code]
I used this because with sprites it works, but using it with labels I get this warning and the label won't change:
Warning cocosnode may not respond to -setString
How come? What is the correct way to update a label inside another layer? Also where is the correct place to update this? I mean: I have a layer for the background, a layer with the sprite and a layer with the score, whenever I click the sprite the score would increase, where the logic of this should be put? In the sprite layer? In the label layer? or in a completely different layer that hold the logic?
Thank you very much for your time and for your wonderful sdk!