blob: 655d1a4e7788c05d2c9e4b0d967aacad08cb74a3 (
plain)
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
|
game.animation = function(character, dt)
local frameStart = function()
character.currentFrame = 1
end
local frameCounter = function()
character.currentFrame = character.currentFrame + 1
end
local animationStart = function()
character.elapsedTime = character.elapsedTime + dt
end
local animationCounter = function(value)
if character.elapsedTime >= (1 / character.fps) then
character.elapsedTime = character.elapsedTime - (1 / character.fps)
if character.currentFrame == # character then
frameStart()
if value == 'start' then
loopCounter = 1
elseif value == 'counter' then
loopCounter = loopCounter + 1
end
else
frameCounter()
end
end
end
local animationEnd = function()
character.elapsedTime = 0
end
if type(character.loop) == 'number' and character.loop > 0 then
if loopCounter == nil then
animationStart()
animationCounter('start')
elseif loopCounter < character.loop then
animationStart()
animationCounter('counter')
else
animationEnd()
frameStart()
end
elseif character.loop == 0 or character.loop == false then
animationEnd()
frameStart()
elseif character.loop == -1 or character.loop == true then
animationStart()
animationCounter()
end
end
|