2016-09-26 168 views
0

我正在創建一個遊戲,您必須儘可能多地點擊10秒鐘的圈子。如果用戶點擊了一圈,計數器+ = 0.15毫秒,但如果他錯過它,反= 0.15如何在倒數計時器標籤中顯示毫秒數?

timer = Timer.scheduledTimer(timeInterval: 1, target: self, selector: #selector(GameScene.updateTimer), userInfo: nil, repeats: true) 

現在,這是定時器功能:

func updateTimer() { 
    counter-=1 
    timerLabel.text = "\(counter)" 
    if counter == 0 { 
     timerLabel.fontColor = UIColor.red 
     timerLabel.text = "TIME'S UP" 
     resetGameLabel.isHidden = false 
     Circle.removeFromParent() 
     timer.invalidate() 
    } 
    if counter < 0 { 
     timerLabel.fontColor = UIColor.red 
     timerLabel.text = "TIME'S UP" 
     resetGameLabel.isHidden = false 
     Circle.removeFromParent() 
     timer.invalidate() 
    } 
} 

現在,我要的是顯示該timerLabel.text毫秒,我該怎麼辦?

+0

僅供參考,定時器不能保證在一秒鐘內觸發,只有當它的運行迴路超出允許的時間時 – Knight0fDragon

回答

0

希望這有助於:

func currentTimeInMilliSeconds()->Int64 { 
    return Int64(Date().timeIntervalSince1970 * 1000) 
} 

var counterInMilliSeconds = currentTimeInMilliSeconds() 
0

如果您創建一個VAR timeToDisplay:雙並使其等於的時候,你可以添加或刪除你想要的毫秒,然後只是使標籤等於VAR timeToDisplay而不是你的櫃檯。

+0

通過增加或刪除毫秒,你的意思是什麼?我怎樣才能做到這一點?例? – safasfmasklfalskf

+0

像timetoDisplay - = 0.5或timetoDisplay + = 0.5 –