开发者

how to do a running score animation in iphone sdk

开发者 https://www.devze.com 2023-02-07 12:26 出处:网络
I wish to do a running score animati开发者_开发知识库on for my iphone app in xcode such that whenever I increase the score by an integer scoreAdded, the score will run up to the new score instead of b

I wish to do a running score animati开发者_开发知识库on for my iphone app in xcode such that whenever I increase the score by an integer scoreAdded, the score will run up to the new score instead of being updated to the new score. I try some for loop with sleep but to no available. So I'm wondering if there's any way of doing it. Thank you.


Add a timer that will call a specific method every so often, like this:

NSTimer *tUpdate;
NSTimeInterval tiCallRate = 1.0 / 15.0;
tUpdate = [NSTimer scheduledTimerWithTimeInterval:tiCallRate
                                           target:self
                                         selector:@selector(updateScore:)
                                         userInfo:nil
                                          repeats:YES]; 

This will call your updateScore method 15 times a second

Then in the main part of your game, instead of simply adding the amount to currentScore, I would instead store the additional amount in a separate member variable, say addToScore. e.g.

addToScore = 10;

Your new method updateScore would have a bit of code like this:

if (addToScore)
{
    addToScore--;
    currentScore++;
    // Now display currentScore
}


Try redrawing the view after each iteration where your score is being displayed:

for (/* loop conditions here */) {
    score += 1;
    [scoreView setNeedsDisplay:YES];
}
0

精彩评论

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