我一直試圖弄清楚如何更新分數。我有一個字符串的標籤,該得分的推移,但它不更新更新分數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];
那麼這就是在得分後加入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;
}
,並建議之間的碰撞上,因爲scoreLabel拒絕衝突已檢測
日以後更新我能怎麼更新ank you:D
cclabelttf很慢,當串改變(夠慢的每次字符串修改通知口吃),對於經常更新標籤一個cclabelbmfont或cclabelatlas是更好的選擇 – LearnCocos2D