如何做到在iPhone SDK的运行比分动画 [英] how to do a running score animation in iphone sdk

查看:90
本文介绍了如何做到在iPhone SDK的运行比分动画的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望为以x code我的iPhone应用程序做了运行得分动画这样,每当我增加一个整数scoreAdded比分,将比分运行到新的成绩,而不是被更新到新的评分。我尝试一些for循环的睡眠,但没有用。所以,我想知道是否有这样做的任何方式。谢谢你。

I wish to do a running score animation 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]; 

这将调用您的 updateScore 方式15次的速率

This will call your updateScore method 15 times a second

然后在你的游戏中的主要部分,而不是简单地增加量为 currentScore 后,我反而存储在单独的成员变量的附加额,说的 addToScore 。例如。

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;

您新方法的 updateScore 将有一个位code像这样的:

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

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

这篇关于如何做到在iPhone SDK的运行比分动画的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆