Waiting in coroutines
yield waits for a tween or a timer:
func Die() coroutine {
yield tween.ToFloat(node, "SpriteRenderer.Tint.a", 0, 0.2, curve.OutQuad)
node.Destroy()
}
func Spawner() coroutine {
t := timer.New(2).Repeat(-1)
for {
yield t
spawn()
}
}
How waits resume:
yield tresumes on the frame after the tween ends or is stopped, or after the timer fires or is cancelled.- A repeating timer wakes the coroutine on every fire.
- A
nilor finished handle resumes on the next frame. - Woken coroutines run with the other game-time coroutines, so they wait while the game is paused even when the tween or timer itself is unscaled. In a pause menu, wait with
yield waitUnscaled(s).
There is no polling: a coroutine parked on a handle costs nothing until the handle wakes it.