开发者

How to animate label's value in cocos2d?

开发者 https://www.devze.com 2022-12-22 21:30 出处:网络
I am making a slot machine game in iphone. I am using cocos2d as its language. I am greatly disturb coding for the method that will animate score in the game. The animation looks like with the fps. Ca

I am making a slot machine game in iphone. I am using cocos2d as its language. I am greatly disturb coding for the method that will animate score in the game. The animation looks like with the fps. Can you help me do it. Animating t开发者_StackOverflow社区he score in cocos2d. Can you share sample code that looks like what i need now. Thanks in advance.


Here is how I do my score. it is not really animated, but if you want it to be like fps this will do it. Just call this method when your score changes.

in your init method:

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

This is the score update method:

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

Then to update the score when the score changes call it like this:

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


I've done it in this way:

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

and

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

精彩评论

暂无评论...
验证码 换一张
取 消