Timers
Timers belong to the instance and count in steps: 60 steps = 1 second.
| Function | What it does |
|---|---|
after(steps, fn) |
Calls fn once, steps steps from now. Returns the timer id. |
afterSeconds(seconds, fn) |
The same, in seconds. |
every(steps, fn) |
Calls fn every steps steps, until cancelled. |
cancel(id) |
Cancels a timer of this instance. |
tween(...) |
Takes a value from one point to another over a time, with a curve: linear, in, out, inOut or back. |
function onSpawn(self) self:after(30, function() self.visible = true end) self.tiro = self:every(60, function() spawn("Bullet", self.x, self.y, "Instancias") end)
self:tween({ y = self.y - 20 }, 0.3, "out")endvoid onSpawn() override { after(30, [this] { visible = true; }); tiro_ = every(60, [this] { spawn<Bullet>(x, y, "Instancias"); });
tween(y, y - 20, 0.3f, [this](float v) { y = v; }, Ease::Out);}Sequences (Lua)
Section titled “Sequences (Lua)”self:run(fn) runs a function that can wait midway. The waits pause only the sequence.
| Function | What it does |
|---|---|
wait(seconds) |
Continues after that many seconds. |
waitSteps(steps) |
Continues after that many steps. |
waitUntil(fn) |
Continues when fn returns true. |
self:run(function() wait(2) spawn("Chefe", 160, 40, "Instancias") waitUntil(function() return not any("Chefe") end) fadeTo("Vitoria")end)- Timers run at the start of the step, before
onUpdate. - When the instance is destroyed, its timers and sequences end.
- In Lua,
tweenaccepts several fields and a function for the end:self:tween({ x = 100, angle = 90 }, 1, "inOut", fn).
