diff --git a/entity.lua b/entity.lua index 681e83f..c7a2381 100644 --- a/entity.lua +++ b/entity.lua @@ -22,9 +22,10 @@ function Entity:initialize(t) self.drawOffset = {x = 0, y = 0} if self.size.w < 1 or self.size.h < 1 then -- Small sprites (notably 10px switches) are drawn inside a 16px cell. - -- Offset by the leftover space, not by half their own size. - self.drawOffset.x = drawScale * (16 - self.spriteSize.w) / 2 - self.drawOffset.y = drawScale * (16 - self.spriteSize.h) / 2 + -- Offset by the leftover space in native sprite-pixels (e.g. (16-10)/2 = 3); + -- drawScale is applied at draw time so this stays correct across resizes. + self.drawOffset.x = (16 - self.spriteSize.w) / 2 + self.drawOffset.y = (16 - self.spriteSize.h) / 2 end end @@ -121,7 +122,7 @@ function Entity:draw(channel) if not sprite then return end love.graphics.setColor(gColor[channel]:set()) local p = self:getDrawPos() - love.graphics.draw(sprite, p.x + self.drawOffset.x, p.y + self.drawOffset.y, 0, drawScale, drawScale) + love.graphics.draw(sprite, p.x + self.drawOffset.x * drawScale, p.y + self.drawOffset.y * drawScale, 0, drawScale, drawScale) end function Entity:canMove()