我使用了来自http://www.raywenderlich.com/25736/how-to-make-a-simple-iphone-game-with-cocos2d-2-x-tutorial的cocos2d游戏教程。在我将得分添加到得分标签后,得分增加但是之前的得分没有被删除,新得分被添加到早期得分的标签之上
代码:
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 :(得分:0)
我猜你在更新方法中做了这一切,每次更新时都添加了label1标签。您可能需要在.h文件中为分数label1创建一个iVar,在init中初始化它,如下所示:
in .h
CCLabelTTF *label1;
in .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];