2010-03-16 37 views
0

我正在iphone上製作老虎機遊戲。我使用cocos2d作爲它的語言。我很大程度上打擾了編寫遊戲中動畫分數的方法。動畫看起來像fps。你能幫我做到嗎?在cocos2d中設置動畫分數。你能分享看起來像我現在需要的示例代碼嗎?提前致謝。如何在cocos2d中動畫標籤的值?

+0

對不起,你想幹什麼?動畫標籤做什麼?像打字機效果一樣? – 2010-03-16 10:31:15

回答

0

這是我如何做我的分數。它並不是真正的動畫,但是如果你想讓它像fps一樣,這將會實現。只要你的分數改變,就調用這個方法。

在您的init方法:

// create and initialize the _scoreLabel 
    _scoreLabel = [CCLabel labelWithString:@" " 
          dimensions:CGSizeMake(labelSizes.width,labelSizes.height) 
          alignment:UITextAlignmentLeft 
          fontName:@"Helvetica" 
          fontSize:20.0]; 
    _scoreLabel.color = ccc3(255,255,255); 
    _scoreLabel.position = ccp((labelSizes.width/2), (winSize.height - (labelSizes.height/2))); 
    [self addChild:_scoreLabel z:1]; 

這是得分更新方法:

-(void)updateScore { 
    [_scoreLabel setString:[NSString stringWithFormat:@"Score: %d/%d", _score, _scoreToWin]]; 
} 

然後更新當比分改變調用它的分數:

// Then later to set the Score 
    [self updateScore]; 
+0

這只是更新比分只知道!!!他需要視覺動畫的分數! – 2012-05-25 21:51:08

0

我這樣做過:

_odd = _odd + _stage*value; 
[self schedule:@selector(pointAdder) interval:1.0/(3.0*_odd)]; 

- (void)pointAdder { 
    if (_odd==0) { 
     [self unschedule:@selector(pointAdder)]; 
     return; 
    } 
    else { 
     int tmp = [_lblScore.string intValue]; 
     [_lblScore setString:[NSString stringWithFormat:@"%i",tmp+1]]; 
     _odd--; 
    } 
}