- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathanimate.lua
More file actions
Latest commit
90 lines (72 loc) · 2.05 KB
/
Copy pathanimate.lua
File metadata and controls
90 lines (72 loc) · 2.05 KB
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
-- animate.lua : helpers for animating
localanimate= {}
animate.timer='animateTimer'
globals.timer.track(animate.timer)
globals.timer.start(animate.timer)
localfunctionparseOptions(options)
ifnotoptionsthen
options= {}
end
options.speed=options.speedor1
options.timer=options.timeroranimate.timer
options.factor=options.factoror10
options.frames=options.framesor2
ifoptions.loop==nilthen
options.loop=true
end
returnoptions
end
localfunctiongetFrame(animatable)
-- if we're not animating anymore, just return the last frame
ifanimatable.animatingthen
localframe=
(math.floor(animatable.options.speed
*globals.timer.getTime(animatable.options.timer))
%animatable.options.frames ) +1
-- if at the last frame of the loop set not animating anymore if
-- looping is disabled
ifanimatable.options.loop==false
andframe==animatable.options.framesthen
animatable.animating=false
end
returnframe
else
returnanimatable.options.frames
end
end
functionanimate:new(options)
localobj= {
animating=true,
options=parseOptions(options),
}
self.__index=self
returnsetmetatable(obj, self)
end
functionanimate.reset()
globals.timer.reset(animate.timer)
end
functionanimate:jump(drawable, x, y)
localframe=getFrame(self)
ifframe==1then
love.graphics.draw(drawable, x, y-self.options.factor)
elseifframe==2then
love.graphics.draw(drawable, x, y)
end
end
functionanimate:blinkText(text)
localframe=getFrame(self)
ifframe==1then
return''
elseifframe==2then
returntext
end
end
functionanimate:teletype(text)
self.options.frames=string.len(text) +1
localframe=getFrame(self)
returnstring.sub(text, 1, frame-1)
end
functionanimate:replay()
self.animating=true
end
returnanimate