2010-12-14 63 views
0

我想,當一個目標是打造成得分...如何才能創造出得分的iPhone遊戲

每當目標被擊中

int targetHit=0; 
targerhit=targethit+1; 

現在我想表明,在標籤.. ..

CCLabel* label2 = [CCLabel labelWithString:@"null" <-----i want to add score herer?and keep changing it ?how can i 
             fontName:@"Marker Felt" 
             fontSize:30]; 
     label2.position = ccp(400, 295); 


     [self addChild:label2]; 

回答

0

假設您具有與CCLabel scoreLabel關聯的整數分數和String scoreString。這些三元素都必須是你的類的屬性(也許是一個CCLayer)。 現在,如果您只想更新scoreLabel,您必須:

//create a range object 
NSRange range; 
//it starts from the first character(0) and ends at the scoreString length 
range.location=0; 
range.length = [scoreString length]; 
//then delete the characters of the string which fall in the range (that means all) 
[scoreString deleteCharactersInRange:range]; 
//then use appendFormat to update the scoreString with the latest score value 
[scoreString appendFormat:@"%07d",score]; 
//therefore update the label 
[scoreLabel setString:scoreString]; 
0

我沒有使用cocos2d,但是這裏有一些我發現的信息。

  • (空)了setString:(的NSString *)字符串

    改變字符串來呈現

    警告: 更改字符串是創建一個新的CCLabel昂貴。