summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJorge Lopez Seijas <jorginho@riseup.net>2016-12-13 21:18:38 +0100
committerJorge Lopez Seijas <jorginho@riseup.net>2016-12-13 21:18:38 +0100
commit76490cde2af5d2ef71bf4c6474c38fdb4b236e17 (patch)
treec0cb50670496291672a4fd58b6b4c028bf99e639
parentb740887cbed3bb9e1a8e139a3bbbb35146749d52 (diff)
Simplifying animation function
-rw-r--r--src/gnu_and_bola_-_the_libre_beat_em_up_game/main.lua33
1 files changed, 12 insertions, 21 deletions
diff --git a/src/gnu_and_bola_-_the_libre_beat_em_up_game/main.lua b/src/gnu_and_bola_-_the_libre_beat_em_up_game/main.lua
index a938243..f1fa96f 100644
--- a/src/gnu_and_bola_-_the_libre_beat_em_up_game/main.lua
+++ b/src/gnu_and_bola_-_the_libre_beat_em_up_game/main.lua
@@ -147,30 +147,21 @@ end
function love.update(dt)
nextTime = nextTime + (1 / fps)
- animation = function(character, metaSprites, 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()
- if character.elapsedTime >= (1 / character.fps) then
- character.elapsedTime = character.elapsedTime - (1 / character.fps)
- if character.currentFrame == # character then
- frameStart()
- else
- frameCounter()
- end
+ animation = function(quad, metaSprites, dt)
+ --Increase actual elapsed time with new dt
+ quad.elapsedTime = quad.elapsedTime + dt --AnimationStart
+
+ --In order to know if it is necessary to change the frame
+ if quad.elapsedTime >= (1 / quad.fps) then
+ quad.elapsedTime = quad.elapsedTime - (1 / quad.fps)
+ if quad.currentFrame == # quad then --If current frame is equal to long quad list
+ quad.currentFrame = 1 -- Return to first frame
+ else
+ quad.currentFrame = quad.currentFrame + 1 --Next frame
end
end
- animationStart()
- animationCounter()
- metaSprites.quad = character[character.currentFrame]
+ metaSprites.quad = quad[quad.currentFrame] --Update with new fame
end
animation(quad.bola, metaSprites.bola, dt)