更新分数Cocos2d 3.0

时间:2014-02-12 07:11:42

标签: ios cocos2d-iphone cclabelttf

我一直想弄清楚如何更新分数。我有一个带有字符串的标签,该分数会继续,但不会更新

这是标记,其中包含要更新的分数

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

2 个答案:

答案 0 :(得分:2)

您需要更新更新分数的scoreLabel。

所以之后,

 score++;

包括

[scorelabel setString:[NSString stringWithFormat:@"score: %d",score]];

答案 1 :(得分: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]];