我正在创建一个游戏。当用户完成游戏时,我正在向他展示分数。为了使其具有交互性,我将分数从 0 计算到分数。
现在,由于用户可以赚取 10 分或 100,000,我不想让他等太久,所以我希望无论分数如何,总时间都是固定的。
所以我这样做了,但似乎计时器间隔不受间隔值的影响。
哪里有问题 ?
///score timer
-(void)startScoreCountTimer:(NSNumber*)score{
finishedGameFinalScore = [score integerValue];
CGFloat finishedGameFinalScoreAsFloat = [score floatValue];
CGFloat interval = 2.0f/finishedGameFinalScoreAsFloat;
NSLog(@"interval = %f",interval);
NSDate *fireDate = [NSDate dateWithTimeIntervalSinceNow:0];
timer = [[NSTimer alloc] initWithFireDate:fireDate
interval:interval
target:self
selector:@selector(timerMethod:)
userInfo:nil
repeats:YES];
NSRunLoop *runLoop = [NSRunLoop currentRunLoop];
[runLoop addTimer:timer forMode:NSDefaultRunLoopMode];
}
- (void)timerMethod:(NSTimer*)theTimer{
scoreCount++;
finalScoreLabel.text = [NSString stringWithFormat:@"%i",scoreCount];
if (scoreCount == finishedGameFinalScore ||finishedGameFinalScore ==0) {
[theTimer invalidate];
scoreCount=0;
[self updateMedalsBoard];
}
}