anim(
spec) ->anim,err
Create an animated sprite from a frame sequence
| spec field | description |
|---|---|
frames | an array of sprites; with sheet, an array of frame indices or names |
sheet | the sheet frames names |
durations | seconds per frame: one number for all, or an array; default 0.1 |
loop | true (default) loops forever, false stops on the last frame, a number loops that many times |
on_end | fn(anim), called once when the animation finishes |
A durations array shorter than the frames repeats its last entry. A
duration of 0 or less answers nil and an error: update steps the clock
down by a frame's duration until it falls under, which a nought never does.
The anim blits as its current frame. Call anim:update(dt) each tick, then
canvas:blit(anim, x, y).
| method | description |
|---|---|
anim:update(dt) | advance by dt seconds; holds the last frame once finished |
anim:current() | the current frame's sprite |
anim:done() | true once finished |
anim:reset() | back to the first frame, unfinished |