gfx.sprite.anim

gfx.sprite

anim(spec) -> anim, err

Create an animated sprite from a frame sequence

spec fielddescription
framesan array of sprites; with sheet, an array of frame indices or names
sheetthe sheet frames names
durationsseconds per frame: one number for all, or an array; default 0.1
looptrue (default) loops forever, false stops on the last frame, a number loops that many times
on_endfn(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).

methoddescription
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