From ffa39098879c1a8a52209e77a723c3f79a109fa0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Erkki=20Sepp=C3=A4l=C3=A4?= Date: Sun, 19 Oct 2014 03:26:23 +0300 Subject: [PATCH] Animation: fixed --- entities/animation.lua | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/entities/animation.lua b/entities/animation.lua index 8d3f837..3b35ecb 100644 --- a/entities/animation.lua +++ b/entities/animation.lua @@ -6,31 +6,32 @@ Animation = Class{ frames = {}, - curFrame = 0 + curFrame = 0, init = function(self, x, y, level, basename, numFrames, fps) Entity.init(self, x, y, level) - for frame = 0,numFrames - 1 do + for frame = 0, numFrames - 1 do self.frames[frame] = love.graphics.newImage(string.format(basename, frame)) end + self.fps = fps self.angle = 0 - self.width = self.frames[0].getWidth(); - self.height = self.frames[0].getHeight(); + self.x = x + self.y = y + self.width = self.frames[0]:getWidth(); + self.height = self.frames[0]:getHeight(); self.quad = love.graphics.newQuad(0, 0, self.width, self.height, self.width, self.height) end; draw = function(self) - if self.health > 0 then - local img = self.frames[math.floor(curFrame)] - if img then - love.graphics.draw(self.frames[0], self.quad, 0, 0, self.angle, 1, 1, self.width / 2, self.width / 2) - end + local img = self.frames[math.floor(self.curFrame)] + if img then + love.graphics.draw(img, self.quad, self.x, self.y, self.angle, 1, 1, self.width / 2, self.width / 2) end end; update = function(self, dt) - curFrame += dt * fps + self.curFrame = self.curFrame + dt * self.fps end; }