diff --git a/timer.lua b/timer.lua index 07712cc..e25a958 100644 --- a/timer.lua +++ b/timer.lua @@ -22,6 +22,7 @@ function timer:new(time, on_progress, on_finish) self.timer = 0 self.on_progress = on_progress self.on_finish = on_finish + self.has_expired = false self:reset(time) end @@ -30,7 +31,8 @@ function timer:update(dt) if not self:expired() then self.timer = self.timer + dt - --get the relevant callback + --set the expired state and get the relevant callback + self.has_expired = self.timer >= self.time local cb = self:expired() and self.on_finish or self.on_progress @@ -43,7 +45,7 @@ end --check if the timer has expired function timer:expired() - return self.timer >= self.time + return self.has_expired end --get the timer's progress from 0 to 1