美好的一天! 我想用SKLabel制作一个计时器,以毫秒为单位计算时间。但我这样做的时间只有这样:
SKLabelNode *countDown = [SKLabelNode labelNodeWithFontNamed:@"Chalkduster"];
countDown.position = CGPointMake(10, -20);
countDown.horizontalAlignmentMode = SKLabelHorizontalAlignmentModeLeft;
countDown.fontSize = 20;
[bonus_10 addChild: countDown];
// Initialize the countdown variable
__block float countDownInt = i;
// Define the actions
SKAction *updateLabel = [SKAction runBlock:^{
countDown.text = [NSString stringWithFormat:@"%f", countDownInt];
countDownInt = countDownInt-0.1;
}];
// Create a combined action
SKAction *updateLabelAndWait = [SKAction sequence:@[updateLabel, wait]];
// Run action "seconds" number of times and then set the label to indicate
// the countdown has ended
[self runAction:[SKAction repeatAction] completion:^{
countDown.text = @"Time's Up";
}];
有没有机会在几毫秒内做定时器?谢谢!
答案 0 :(得分:2)
如果您可以跳过几毫秒的显示,我会使用更新方法。
这样的事情:
equal_range
答案 1 :(得分:1)
如果您将秒数放在此处作为小数(如来自更新),则会将其格式化为
分:秒:十分之一秒
func timeString(seconds : CGFloat) -> String {
// 90 seconds = 1.5
let minutesFloat = seconds / 60
// 1.5 = 1
let minutes = floor(minutesFloat)
// (1.5 - 1) * 60 = 30.01
let secondsFloat = (minutesFloat - minutes) * 60
// 30.01 = 30
let secs = floor(secondsFloat)
// (30.01 - 30) * 100 = 1.0
let secsDec = floor((secondsFloat - secs) * 100)
return String(format: "%02d:%02d:%02d", Int(minutes), Int(secs), Int(secsDec))
}