blob: e0e98a03912e85c9d11e76ae870e89aa28b62e3d (
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
49
50
51
52
53
|
game.animation = function(character, dt)
-- frameRestart = 0
local frameStart = function()
character.currentFrame = 1
end
local frameCounter = function()
--[[ if character.restart == true then
character.currentFrame = character.currentFrame + 1 - frameRestart
else]]
character.currentFrame = character.currentFrame + 1
-- end
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
|