聽起來像一個Timer會做的正是你要尋找的。
設置一個全局定時器變量var,間隔取決於您希望得分系統的精確程度,並用每個新問題進行啓動。當用戶回答時,請檢查該計時器的repeatCount
以查看他們正確回答需要多長時間。
public class Quiz{
private var mTimer:Timer;
...
public function Quiz():void{
// This creates a timer that will fire every 100 ms for 50 times.
// If you want a more precise scoring system, reduce the delay, and increase the count
mTimer = new Timer(100, 50);
}
private function newQuestion():void{
// Don't forget to reset the timer for every new question
mTimer.reset();
mTimer.start();
}
private function onRightAnswer():void{
// Check how many times the timer fired already
var count:int = mTimer.currentCount;
// Deduce points for every count
var score:int = 500 - (count * 10);
}
...
}
輝煌,這看起來像一個奇妙的地方開始!謝謝 – Esyem
'repeatCount'記錄你的計時器在停止之前會發射多少次。它實質上是您在創建計時器時給出的第二個參數。在我的例子中,'repeatCount'將始終爲50.如果您希望計時器上剩餘的時間百分比'100.0 *(mTimer.currentCount/mTimer.repeatCount)',那麼這很有用。如果您希望計時器比預期更早停止,則還可以在運行時對其進行修改。 –
謝謝,有用的信息! – Esyem