0

我一直在试图弄清楚如何更新分数。我有一个带有分数的字符串标签,但它没有更新

这是带有假设要更新的分数的标签

score=0;
CCLabelTTF *scorelabel = [CCLabelTTF labelWithString:[NSString stringWithFormat:@"score: %d",score] fontName:@"Verdana-Bold" fontSize:18.0f];
scorelabel.positionType = CCPositionTypeNormalized;
scorelabel.color = [CCColor blackColor];
scorelabel.position = ccp(0.85f, 0.95f); // Top Right of screen
[self addChild:scorelabel];

然后这是在两个精灵之间发生碰撞后添加分数的地方

- (BOOL)ccPhysicsCollisionBegin:(CCPhysicsCollisionPair *)pair monsterCollision:(CCNode *)monster projectileCollision:(CCNode *)projectile {
//Creating another sprite on the position the monster one was.
CCSprite *explosion = [CCSprite spriteWithImageNamed:@"explosion.png"];
explosion.position = monster.position;
[self addChild:explosion];
[[OALSimpleAudio sharedInstance] playEffect:@"exsound.mp3"];

CCActionDelay *delay = [CCActionDelay actionWithDuration:.0f];
CCActionFadeOut *fade = [CCActionFadeOut actionWithDuration:.4f];
[explosion runAction:[CCActionSequence actionWithArray:@[delay,fade]]];

[monster removeFromParent];
[projectile removeFromParent];

score++;

return YES;
}

并建议我如何更新它,因为在检测到碰撞后 scoreLabel 拒绝更新

谢谢 :D

4

2 回答 2

2

您需要在更新分数的地方更新 scoreLabel。

所以之后,

 score++;

包括

[scorelabel setString:[NSString stringWithFormat:@"score: %d",score]];
于 2014-02-12T07:24:02.547 回答
0

更新分数

@Implement(在最顶端)

CCLabelTTF *scorelabel;

显示分数的标签

score=0;
scorelabel = [CCLabelTTF labelWithString:[NSString stringWithFormat:@"score: %d",score] fontName:@"a2203.ttf" fontSize:18.0f];
scorelabel.positionType = CCPositionTypeNormalized;
scorelabel.color = [CCColor blackColor];
scorelabel.position = ccp(0.85f, 0.95f); // Top Right of screen
[self addChild:scorelabel];

score++;

[scorelabel setString:[NSString stringWithFormat:@"score: %d",score]];
于 2014-02-13T07:08:54.167 回答