gpt4 book ai didi

ios - 更新评分 Cocos2d 3.0

转载 作者:行者123 更新时间:2023-11-28 22:15:49 25 4
gpt4 key购买 nike

我一直在想办法更新分数。我有一个带有分数的字符串的标签,但它不会更新

这是应该更新分数的标签

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

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

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

最佳答案

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

所以之后,

 score++;

包含

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

关于ios - 更新评分 Cocos2d 3.0,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21721046/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com