platformer moving background and enviroment

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
mufty
Prole
Posts: 10
Joined: Fri Apr 09, 2010 5:11 pm

platformer moving background and enviroment

Post 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.
Attachments
gongo.love
(830.08 KiB) Downloaded 200 times
Last edited by mufty on Fri Apr 09, 2010 8:28 pm, edited 2 times in total.
User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: platformer moving background and enviroment

Post by bartbes »

Is it possible the body rotates?
mufty
Prole
Posts: 10
Joined: Fri Apr 09, 2010 5:11 pm

Re: platformer moving background and enviroment

Post by mufty »

bartbes wrote:Is it possible the body rotates?
I don't get it how should it rotate? I'm not rotating it.
User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: platformer moving background and enviroment

Post 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.
mufty
Prole
Posts: 10
Joined: Fri Apr 09, 2010 5:11 pm

Re: platformer moving background and enviroment

Post 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
User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: platformer moving background and enviroment

Post by bartbes »

Well, then there is the question, is the image the same size?
mufty
Prole
Posts: 10
Joined: Fri Apr 09, 2010 5:11 pm

Re: platformer moving background and enviroment

Post 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
User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: platformer moving background and enviroment

Post by bartbes »

Can you draw a box around the shape?
mufty
Prole
Posts: 10
Joined: Fri Apr 09, 2010 5:11 pm

Re: platformer moving background and enviroment

Post 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
User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: platformer moving background and enviroment

Post 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!
Post Reply

Who is online

Users browsing this forum: Google [Bot] and 2 guests