Hi guys so I've fell in LOVE and I've a little issue with moving physic enviroment elements as the player reach some point to the right or left all elements and background should move. Well everything is moving the right way but there is some strange offset while moving that little platform, its physic body moves a little more then the image representing it. I'm doing it in Ground class and method draw which has one attribute x as an offset for the current position to be exactly correct in this part of the code:
function Ground:draw(x)
if self.x > x then
self.body:setPosition(self.body:getX() + 6, self.body:getY())
elseif self.x < x then
self.body:setPosition(self.body:getX() - 6, self.body:getY())
end
love.graphics.draw(self.img, (self.body:getX() - self.img:getWidth()/2), self.body:getY() - self.img:getHeight()/2)
self.x = x
end
It should move the body by 6 points if the offset is greater or lower then the last one and it does but the image is not representing its current position like it should. Is there anything I'm doing wrong? I've been trying to find a solution to this in one mario port found here but seems not to work for me. Logicaly the body has its center in its absolute center no offset there and the image at the upper left corner or am I wrong? Please help me out with this.
bartbes wrote:Collisions.
And, how do you know the body moves?
Also, I'd recommend you take a look at the offset parameters to love.graphics.draw.
it has mass 0 so it should be static and collisions shouldn't rotate or in anyway move it. I know that the body moves because i can jump on it in empty space which isn't the place where the image is. And the offset yes i know but even with the code like this it's doing the same thing:
function Ground:draw(x)
if self.x > x then
self.body:setPosition(self.body:getX() + 6, self.body:getY())
elseif self.x < x then
self.body:setPosition(self.body:getX() - 6, self.body:getY())
end
love.graphics.draw(self.img, self.body:getX(), self.body:getY(), 0, 1, 1, self.img:getWidth()/2, self.img:getHeight()/2)
self.x = x
end
bartbes wrote:Can you draw a box around the shape?
hmm that's wierd because the shape is in the position like image and is matching its position but the body isn't... see updated love file with the box around the shape
Found the problem, you will see it when you draw the box around the player shape, you'll see the bounding boxes actually collide correctly.
(btw, you can draw a bounding box using love.graphics.polygon("line", self.shape:getPoints()), which might be a lot easier, and supports non-square bounding 'boxes')