iphone - Displaying score overlapping -


i used cocos2d game tutorial http://www.raywenderlich.com/25736/how-to-make-a-simple-iphone-game-with-cocos2d-2-x-tutorial after add score scorelabel, score increases previous score isn't getting removed , new score gets added above earlier score's label

code:

cgsize winsize = [[ccdirector shareddirector] winsize]; cclabelttf * label1 = [cclabelttf labelwithstring:@"_monsterdestroyed" fontname:@"arial" fontsize:32]; score=score + 2;  [label1 setstring:[nsstring stringwithformat:@"%d",score]];  label1.color = ccc3(0,0,0); label1.position = ccp(winsize.width/2, winsize.height/2); [self addchild:label1]; 

i guessing doing in update method, adding label1 label @ every update. want ivar in .h file score label1 , initialize in init, follows:

in .h

cclabelttf *label1; 

in .m

-(id) init {     if (self = [super init]) {         // existing code, add following         cgsize winsize = [[ccdirector shareddirector] winsize];          label1 = [cclabelttf labelwithstring:@"0" fontname:@"arial" fontsize:32];         label1.color = ccc3(0,0,0);         label1.position = ccp(winsize.width/2, winsize.height/2);         [self addchild:label1];      }       }    // update score  score = score + 2;  [label1 setsting:[nsstring stringwithformat:"%i", score]; 

Comments