From f7811309bcdb66467aed6a5c8c3870d646b5783a Mon Sep 17 00:00:00 2001 From: Aki Date: Sat, 13 Aug 2016 18:19:34 +0200 Subject: floored grid for players and platforms --- ground.lua | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'ground.lua') diff --git a/ground.lua b/ground.lua index 6b0be18..683966b 100644 --- a/ground.lua +++ b/ground.lua @@ -34,16 +34,25 @@ function Ground:delete () self.sprite = nil end +-- Position +function Ground:getPosition() + return self.body:getPosition() +end + -- Draw of `Ground` function Ground:draw (offset_x, offset_y, scale, debug) - -- defaults + -- locals local offset_x = offset_x or 0 local offset_y = offset_y or 0 local scale = scale or 1 local debug = debug or false + local x, y = self:getPosition() + -- pixel grid + 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) - love.graphics.draw(self.sprite, (self.body:getX()+offset_x)*scale, (self.body:getY()+offset_y)*scale, 0, scale, scale) + love.graphics.draw(self.sprite, draw_x, draw_y, 0, scale, scale) -- debug draw if debug then love.graphics.setColor(255, 69, 0, 140) -- cgit v1.1