From c201bef4950138bd8c475d9b8cd1c26e0615145a Mon Sep 17 00:00:00 2001 From: Aki Date: Tue, 12 Sep 2017 19:27:32 +0200 Subject: Removed obsolete offsets and scale from draw of Sprites and children --- not/Hero.lua | 10 +++++----- not/PhysicalBody.lua | 4 ++-- not/Sprite.lua | 14 ++++++-------- not/World.lua | 4 ++-- 4 files changed, 15 insertions(+), 17 deletions(-) diff --git a/not/Hero.lua b/not/Hero.lua index 15cc667..66bc511 100644 --- a/not/Hero.lua +++ b/not/Hero.lua @@ -165,17 +165,17 @@ function Hero:getOffset () return 12,15 end --- Draw of `Hero` -function Hero:draw (offset_x, offset_y, scale, debug) +function Hero:draw (debug) if not self.isAlive then return end - Hero.__super.draw(self, offset_x, offset_y, scale, debug) + Hero.__super.draw(self, debug) end -function Hero:drawTag (offset_x, offset_y, scale) +-- TODO: Hero@drawTag's printf is not readable. +function Hero:drawTag () local x,y = self:getPosition() love.graphics.setFont(Font) love.graphics.setColor(255, 255, 255) - love.graphics.printf(string.format("Player %d", math.abs(self.group)), (math.floor(x)+offset_x)*scale, (math.floor(y)+offset_y-26)*scale,100,'center',0,scale,scale,50,0) + love.graphics.printf(string.format("Player %d", math.abs(self.group)), math.floor(x), math.floor(y)-26 ,100,'center',0,1,1,50,0) end -- Draw HUD of `Hero` diff --git a/not/PhysicalBody.lua b/not/PhysicalBody.lua index 1b2e90d..01a725b 100644 --- a/not/PhysicalBody.lua +++ b/not/PhysicalBody.lua @@ -63,8 +63,8 @@ function PhysicalBody:update (dt) end -- Draw of `PhysicalBody`. -function PhysicalBody:draw (offset_x, offset_y, scale, debug) - PhysicalBody.__super.draw(self, offset_x, offset_y, scale) +function PhysicalBody:draw (debug) + PhysicalBody.__super.draw(self, debug) if debug then for _,fixture in pairs(self.body:getFixtureList()) do local category = fixture:getCategory() diff --git a/not/Sprite.lua b/not/Sprite.lua index 3951e6e..a4346f6 100644 --- a/not/Sprite.lua +++ b/not/Sprite.lua @@ -84,24 +84,22 @@ function Sprite:getOffset () return 0,0 end -- Drawing self to LOVE2D buffer. -- If there is no Quad, it will draw entire image. It won't draw anything if there is no image. +-- TODO: Sprite@draw requires a serious review! -- TODO: it doesn't follow same pattern as `not.Hero.draw`. It should implement so it can be called from `not.World`. -- TODO: change children if above changes are in effect: `not.Platform`, `not.Decoration`. -function Sprite:draw (offset_x, offset_y, scale) - local offset_x = offset_x or 0 - local offset_y = offset_y or 0 - +function Sprite:draw (debug) local i, q = self:getImage(), self:getQuad() local x, y = self:getPosition() local angle = self:getAngle() - local scaleX = self:getHorizontalMirror()*(scale or 1) - local scaleY = self:getVerticalMirror()*(scale or 1) + local scaleX = self:getHorizontalMirror() + local scaleY = self:getVerticalMirror() -- pixel grid ; `approx` selected to prevent floating characters on certain conditions local approx = math.floor if (y - math.floor(y)) > 0.5 then approx = math.ceil end - local draw_y = (approx(y) + offset_y) * scale - local draw_x = (math.floor(x) + offset_x) * scale + local draw_y = approx(y) + local draw_x = math.floor(x) if i then love.graphics.setColor(255,255,255,255) diff --git a/not/World.lua b/not/World.lua index 08b9710..e75880f 100644 --- a/not/World.lua +++ b/not/World.lua @@ -259,10 +259,10 @@ function World:draw () -- TODO: Camera rewrite in progress. for _,entity in pairs(self.entities) do if entity.draw and entity.layer then - entity.layer:renderToWith(self.camera, entity.draw, entity, 0, 0, 1, debug) -- TODO: Offsets and Scale are passed as 0,0,1 in World@draw for compatibility reasons. Remove them. + entity.layer:renderToWith(self.camera, entity.draw, entity, debug) -- TODO: Offsets and Scale are passed as 0,0,1 in World@draw for compatibility reasons. Remove them. end if entity.drawTag then - self.layers[6]:renderToWith(self.camera, entity.drawTag, entity, 0, 0, 1) -- TODO: Offsets and Scale passed. See `World@draw`. + self.layers[6]:renderToWith(self.camera, entity.drawTag, entity, debug) -- TODO: Offsets and Scale passed. See `World@draw`. end end -- cgit v1.1