forked from clowerweb/Lib-Pico8
-
Notifications
You must be signed in to change notification settings - Fork 0
/
animation.lua
46 lines (38 loc) · 889 Bytes
/
animation.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
-- Animation function that supports
-- animation speed, looping (or not looping),
-- stopping on a specific frame, flipping
-- horizontal and/or vertical, and playing
-- in reverse
-- Contributors: Scathe (@clowerweb)
function anim(a,anim,offx,offy)
if(anim.loop!=false) then
anim.loop=true
end
anim.step=anim.step or 0
local sta=anim.start
local cur=anim.current or 0
local stp=anim.step
local spd=anim.speed
local flx=anim.flipx
local fly=anim.flipy
local rst=anim.reset or 0
local lop=anim.loop
local rev=anim.reverse or false
anim.step+=1
stp=anim.step
if(not rev) then
if(stp%flr(30/spd)==0) cur+=1
if(cur==anim.frames) then
if(lop) then cur=0
else cur-=1 end
end
else
if(stp%flr(30/spd)==0) cur-=1
if(cur<0) cur=0
end
anim.current=cur
if(not offx) offx=0
if(not offy) offy=0
spr(sta+cur,a.x+offx,a.y+offy,
1,1,flx,fly)
end -- anim