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

次に、2 つのスプライト間の衝突後にスコアが追加される場所です。

- (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;
}

そして、衝突が検出された後にスコアラベルが更新を拒否するため、更新方法についてアドバイスします

ありがとう: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 に答える