Jin*_*Jin 2 iphone xcode animation
我想在xcode中为我的iphone应用程序做一个运行得分动画,这样每当我用整数得分增加得分时,得分将达到新得分,而不是更新到新得分.我尝试了一些带睡眠的循环,但没有可用.所以我想知道是否有任何方法可以做到这一点.谢谢.
添加一个定时器,每隔一段时间调用一个特定的方法,如下所示:
NSTimer *tUpdate;
NSTimeInterval tiCallRate = 1.0 / 15.0;
tUpdate = [NSTimer scheduledTimerWithTimeInterval:tiCallRate
target:self
selector:@selector(updateScore:)
userInfo:nil
repeats:YES];
Run Code Online (Sandbox Code Playgroud)
这将每秒调用您的updateScore方法15次
然后在游戏的主要部分,而不是简单地将金额添加到currentScore,而是将额外的金额存储在单独的成员变量中,比如addToScore.例如
addToScore = 10;
Run Code Online (Sandbox Code Playgroud)
你的新方法updateScore会有一些像这样的代码:
if (addToScore)
{
addToScore--;
currentScore++;
// Now display currentScore
}
Run Code Online (Sandbox Code Playgroud)