views:

283

answers:

2

hi friends

I am making a game in cocos2d , In that while updating score the old score values get on the label and the new value get overwritten. I m using following code to display the score,

LblScore = [CCLabel labelWithString:[NSString stringWithFormat:@"%d",score] dimensions:CGSizeMake(100, 300) alignment:UITextAlignmentCenter fontName:@"Arial" fontSize:32.0];

Because of this the score value are not shown and all things get massed up, If any one having idea how to update new score?

+2  A: 

I don't completely understand what you are doing, because I can't see all of your code. But, I think what you want is this:

In your scene init:

// Both of these are class variables
score = 0;
LblScore = [CCLabel labelWithString:[NSString stringWithFormat:@"%d",score] dimensions:CGSizeMake(100, 300) alignment:UITextAlignmentCenter fontName:@"Arial" fontSize:32.0];

// Position the score, wherever you want it
[LblScore setPosition: CGPointMake(300, 240)];

When your score changes:

score++ // Not really, but your score changes somehow...
[LblScore setString: [NSString stringWithFormat:@"%d",score]];

This part would probably be in a setScore: or changeScore: method, that changes you internal score value, and changes the label at the same time.

Jeff B
Thanks buddy for your help, but I got the solution.
iPhone Fun
A: 

The Solution for my problem is , I must have to define the label declaration in the -(id)init method, there on the value provided from any where there will be no overwriting of the values.

I've tried it and it's working, But still thanks to all who provided me a help

iPhone Fun