我想在目标被击中时创建得分......
每当目标被击中时
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 :(得分:0)
我还没有使用cocos2d,但这里有一些我发现的信息。
(void)setString:(NSString *)string
更改要渲染的字符串
警告: 更改字符串与创建新的CCLabel一样昂贵。
答案 1 :(得分:0)
假设您有一个整数得分和与CCLabel scoreLabel相关联的String scoreString。这些thre元素必须都是您的类的属性(可能是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];