所以我在应用程序/游戏和其他任何地方都看到了它,当你得分或游戏结束时,得分数加起来从零开始。我想要它,所以在大约1秒内,一个标签从文本:0到和整数,与玩家得分一起存储。
答案 0 :(得分:2)
创建UILabel
以显示分数,并使用NSTimer
更新UILabel
的{{1}}媒体资源。 Apple没有提供能够为您完成所有工作的课程。
答案 1 :(得分:1)
你需要两个变量; currentScore和当前显示的分数。您还需要一个计时器来处理更新ui。
当您的分数发生变化时,请将currentScore更新为您想要的最终分数。然后启动一个计时器,使显示的分数增加,直到它到达那里,即
-(void)scoreUpdater:(NSTimer *)timer {
// Update the score
displayScore ++;
[scoreLabel setText:[NSString stringWithFormat:@"%i", displayScore]];
// Have we got there yet?
if (displayScore == currentScore) {
[scoreTimer invalidate];
[scoreTimer release];
scoreTimer = nil;
}
}
答案 2 :(得分:0)
我会使用NSOperation
睡觉并添加积分(实际上即使没有睡觉也可以工作)。类似的东西:
NSInvocationOperation *op = [[NSInvocationOperation alloc] initWithTarget:self
selector:@selector(updateScore)
object:nil];
[queue addOperation:[op autorelease]];
-(void)updateScore {
while (tot < 1.0) {
displayingScore += score*incr;
tot += incr;
// update score label to displayingScore
[NSThread sleepForTimeInterval:0.05];
}
}