2013-05-06 31 views
0

我使用cocos2d的遊戲教程從http://www.raywenderlich.com/25736/how-to-make-a-simple-iphone-game-with-cocos2d-2-x-tutorial後我添加了比分scorelabel,得分增加,但以前的分數是沒有得到刪除,新的分數較早得分的標籤顯示得分重疊

代碼上面添加得到:

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]; 

回答

0

我猜你正在做更新方法中的所有這些,在每次更新時添加label1標籤。你可能想在比分LABEL1您的.h文件中的伊娃,在你的init,如下所示:

在.H

CCLabelTTF *label1; 

在.M

-(id) init { 
    if (self = [super init]) { 
     // your existing code, add the 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]; 
    }  
} 


// where you update the score 
score = score + 2; 
[label1 setSting:[NSString stringWithFormat:"%i", score];