summaryrefslogtreecommitdiffhomepage
path: root/animated.lua
diff options
context:
space:
mode:
authorAki <nthirtyone@gmail.com>2017-01-20 13:09:03 +0100
committerAki <nthirtyone@gmail.com>2017-01-20 13:09:03 +0100
commit29a527f4dbfeae138b71ce2dd8a82aa40560c522 (patch)
treee55c4764df789e97c72182dc8be9d9f28ca7887d /animated.lua
parent4b2f70d89a53ab03361a51cf970cede2e53cb3f6 (diff)
downloadroflnauts-29a527f4dbfeae138b71ce2dd8a82aa40560c522.zip
roflnauts-29a527f4dbfeae138b71ce2dd8a82aa40560c522.tar.gz
roflnauts-29a527f4dbfeae138b71ce2dd8a82aa40560c522.tar.bz2
Added behaviours for non-animated instances
Diffstat (limited to 'animated.lua')
-rw-r--r--animated.lua26
1 files changed, 19 insertions, 7 deletions
diff --git a/animated.lua b/animated.lua
index 49fcbfa..de16195 100644
--- a/animated.lua
+++ b/animated.lua
@@ -25,6 +25,12 @@ function Animated:getSprite()
return self.sprite
end
+-- Sets new animations list.
+function Animated:setAnimationsList(t)
+ self.animations = t
+ self:setAnimation("default")
+end
+
-- Sets current animation by table key.
function Animated:setAnimation(animation)
self.frame = 1
@@ -38,23 +44,29 @@ end
-- Get frame quad for drawing.
function Animated:getQuad()
- return self.current[self.frame]
+ if self.animations and self.current then
+ return self.current[self.frame]
+ end
end
-- Drawing self to LOVE2D buffer.
+-- If there is no Quad, it will draw entire sprite.
function Animated:draw(...)
local s, q = self:getSprite(), self:getQuad()
- if s and q then
+ if s then
love.graphics.setColor(255,255,255,255)
- love.graphics.draw(s, q, ...)
+ if q then love.graphics.draw(s, q, ...)
+ else love.graphics.draw(s, ...) end
end
end
-- Animation updating.
function Animated:update(dt)
- self.delay = self.delay - dt
- if self.delay < 0 then
- self.delay = self.delay + Animated.delay -- INITIAL from metatable
- self:nextFrame()
+ if self.animations and self.current then
+ self.delay = self.delay - dt
+ if self.delay < 0 then
+ self.delay = self.delay + Animated.delay -- INITIAL from metatable
+ self:nextFrame()
+ end
end
end
-- Moving to the next frame.