Timer
pykraken.Timer A timer for tracking countdown durations with pause/resume functionality.
More about Timer
The Timer class provides a simple countdown timer that can be started, paused, and resumed. It's useful for implementing time-based game mechanics like cooldowns, temporary effects, or timed events.
At a glance
11 membersReference
PYTHON APIConstructor
methodTimer(duration: float)Create a new Timer instance with the specified duration.
Args
- duration (
float) — The countdown duration in seconds. Must be greater than 0.
Raises
- RuntimeError — If duration is less than or equal to 0.
done
propertydone: boolbool: True if the timer has finished counting down, False otherwise.
A timer is considered done when the elapsed time since start (excluding paused time) equals or exceeds the specified duration.
duration
propertyduration: floatGet or set the duration of the timer as a float greater than 0.
elapsed_time
propertyelapsed_time: floatfloat: The time elapsed since the timer was started, in seconds.
Returns 0.0 if the timer hasn't been started. This includes time spent while paused, giving you the total wall-clock time since start().
progress
propertyprogress: floatfloat: The completion progress of the timer as a value between 0.0 and 1.0.
Returns 0.0 if the timer hasn't been started, and 1.0 when the timer is complete. Useful for progress bars and interpolated animations.
time_remaining
propertytime_remaining: floatfloat: The remaining time in seconds before the timer completes.
Returns the full duration if the timer hasn't been started, or 0.0 if the timer has already finished.
pause
methodpause(self) -> NonePause the timer countdown.
The timer will stop counting down but retain its current state. Use resume() to continue the countdown from where it was paused. Has no effect if the timer is not started or already paused.
reset
methodreset(self) -> NoneReset the timer to its initial state.
Stops the timer and resets it back to its initial, unstarted state.
The timer can be started again with start() after being reset.
restart
methodrestart(self) -> NoneRestart the timer countdown.
This is a convenience method that combines reset() and start() into one call.
resume
methodresume(self) -> NoneResume a paused timer countdown.
Continues the countdown from where it was paused. Has no effect if the timer is not started or not currently paused.
start
methodstart(self) -> NoneStart or restart the timer countdown.
This begins the countdown from the full duration. If the timer was previously started, this will reset it back to the beginning.