Обновление счета Cocos2d 3.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

2 ответа

Решение

Чтобы обновить счет

@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]];

Вам нужно обновить ScoreLabel, где вы обновляете счет.

Так после,

 score++;

Включают

[scorelabel setString:[NSString stringWithFormat:@"score: %d",score]];
Другие вопросы по тегам