Timers
var attack timer.Timer
func Ready() {
attack = timer.Cooldown(0.4)
}
func Update(dt float) {
if input.Pressed("Fire") && attack.Use() {
shoot()
}
}
| Function | |
|---|---|
timer.Start(s) Timer |
a one-shot timer; it frees itself when it fires |
timer.New(s) Timer |
a timer that stays after it ends, so Restart can run it again |
timer.Cooldown(s) Timer |
starts ready; Use() takes it and starts the wait |
| Method | |
|---|---|
Repeat(n) Timer |
fire n times, -1 until Cancel |
Unscaled() Timer |
count real time |
Pause(), Resume(), Restart() bool, Cancel() |
control |
Done() bool, Remaining() float, Count() int |
state |
Ready() bool, Use() bool |
cooldowns |
Fired(count int) |
signal, on every fire |
A timer made by a script belongs to that script's node and is cancelled when the node is destroyed. Restart on a one-shot timer that already fired does nothing: its slot is gone. Use timer.New for timers you restart.