Page 1 of 2
platformer moving background and enviroment
Posted: Fri Apr 09, 2010 5:37 pm
by mufty
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:
Code: Select all
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.
Re: platformer moving background and enviroment
Posted: Fri Apr 09, 2010 5:48 pm
by bartbes
Is it possible the body rotates?
Re: platformer moving background and enviroment
Posted: Fri Apr 09, 2010 6:19 pm
by mufty
bartbes wrote:Is it possible the body rotates?
I don't get it how should it rotate? I'm not rotating it.
Re: platformer moving background and enviroment
Posted: Fri Apr 09, 2010 6:24 pm
by bartbes
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.
Re: platformer moving background and enviroment
Posted: Fri Apr 09, 2010 6:44 pm
by mufty
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:
Code: Select all
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
Re: platformer moving background and enviroment
Posted: Fri Apr 09, 2010 7:14 pm
by bartbes
Well, then there is the question, is the image the same size?
Re: platformer moving background and enviroment
Posted: Fri Apr 09, 2010 7:23 pm
by mufty
bartbes wrote:Well, then there is the question, is the image the same size?
yes it is... this is realy strange
... logicaly i don't see any problem in this code it's so simple and it should work but it doesn't
Re: platformer moving background and enviroment
Posted: Fri Apr 09, 2010 7:40 pm
by bartbes
Can you draw a box around the shape?
Re: platformer moving background and enviroment
Posted: Fri Apr 09, 2010 7:57 pm
by mufty
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
Re: platformer moving background and enviroment
Posted: Fri Apr 09, 2010 8:05 pm
by bartbes
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')
EDIT: Oh, and nice graphics!