2010-12-14 2 views
0

목표가 맞았을 때 점수를 만들고 싶습니다 ...어떻게 우리가 아이폰 게임에서 득점을 만들 수 있습니까?

목표에 도달 할 때마다

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이 있다고 가정합니다. 이러한 thre 요소는 모두 클래스의 속성 (어쩌면 CCLayer)이어야합니다. 이제 점수 표를 업데이트하기 만하면됩니다.

//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의 : 문자열을 변경하면 새로운 CCLabel을 만드는 것만 큼 비싸다 (는 NSString *) 문자열

    경고 렌더링하는 문자열을 변경합니다.

관련 문제