diff options
-rw-r--r-- | animated.lua | 12 | ||||
-rw-r--r-- | player.lua | 11 |
2 files changed, 11 insertions, 12 deletions
diff --git a/animated.lua b/animated.lua index 236b68d..49fcbfa 100644 --- a/animated.lua +++ b/animated.lua @@ -11,6 +11,11 @@ Animated = { } Animated.__index = Animated +-- Cleans up reference to sprite on deletion. +function Animated:delete() + self.sprite = nil +end + -- Sets an Image as a sprite. function Animated:setSprite(image) self.sprite = image @@ -38,9 +43,12 @@ end -- Drawing self to LOVE2D buffer. function Animated:draw(...) - love.graphics.draw(self:getSprite(), self:getQuad(), ...) + local s, q = self:getSprite(), self:getQuad() + if s and q then + love.graphics.setColor(255,255,255,255) + love.graphics.draw(s, q, ...) + end end - -- Animation updating. function Animated:update(dt) self.delay = self.delay - dt @@ -52,7 +52,6 @@ function Player:new (game, world, x, y, name) -- Meta local o = {} setmetatable(o, self) - self.__index = self -- Physics local group = -1-#game.Nauts o.body = love.physics.newBody(world, x, y, "dynamic") @@ -79,12 +78,6 @@ function Player:new (game, world, x, y, name) return o end --- Destructor of `Player` -function Player:delete() - -- body deletion is handled by world deletion - self.sprite = nil -end - -- Control set managment function Player:assignControlSet(set) self.controlset = set @@ -303,9 +296,7 @@ function Player:draw(offset_x, offset_y, scale, debug) local draw_x = (math.floor(x) + offset_x) * scale local draw_y = (math.floor(y) + offset_y) * scale -- sprite draw - love.graphics.setColor(255,255,255,255) - Animated.draw(self, draw_x, draw_y, self.rotate, self.facing*scale, 1*scale, 12, 15) - --love.graphics.draw(self:getSprite(), self:getQuad(), draw_x, draw_y, self.rotate, self.facing*scale, 1*scale, 12, 15) + Animated.draw(self, draw_x, draw_y, self.rotate, self.facing*scale, scale, 12, 15) -- debug draw if debug then for _,fixture in pairs(self.body:getFixtureList()) do |