ticker(
fps,opts) ->ticker
Create a frame ticker for a custom loop
For a caller that drives its own loop body; gfx.loop paces its frames on
one. fps defaults to 30. Returns { step = <seconds>, tick = fn }.
ticker:tick() sleeps to the next frame boundary and returns the seconds
since the previous tick and the clock's time; the first tick returns 0 at
once. A tick behind its boundary by less than a step sleeps nought, which
still yields to the tasks sharing the loop; one behind by more starts the
boundary again from now. Call it inside lev.run.
| opts field | description |
|---|---|
clock | what the ticker reads time from, a table with now() and sleep(seconds, token); lev by default. A test hands in one it turns by hand |
token | a cancel token the sleep takes; a tick whose sleep it cancels returns nil and "cancelled", and gfx.loop ends there |