X,Y Coordinates not working properly

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.
Post Reply
User avatar
melexm
Prole
Posts: 8
Joined: Sat Dec 22, 2012 8:01 pm

X,Y Coordinates not working properly

Post by melexm »

Hello,
I would like to get an explanation (I couldn't find anything in the docs) about the x,y coordinates.
I want to create a line which will start from the mouse pressed x,y and end in the mouse released x,y.
Here is the code in the mouse released function event:

Code: Select all

walls[i].s = love.physics.newEdgeShape(mStartX, mStartX, mEndX, mEndY)
It creates an odd line with no angle and only length is chaining.
Why isn't this working? (Link/answer are highly appreciated)

More code:

Code: Select all

function love.mousepressed(x, y, button)
	mStartX = x
	mStartY = y
end
function love.mousereleased(x, y, button)
	walls.count = walls.count + 1
	i = walls.count
	walls[i] = {}
	walls[i].b = love.physics.newBody(world, mStartX, mStartY, "static")
  	walls[i].s = love.physics.newEdgeShape(mStartX, mStartX, mEndX, mEndY) // here
  	walls[i].f = love.physics.newFixture(walls[i].b, walls[i].s, 1 )
  	walls[i].f:setFriction(0.1)
end
coffee
Party member
Posts: 1206
Joined: Wed Nov 02, 2011 9:07 pm

Re: X,Y Coordinates not working properly

Post by coffee »

melexm wrote: walls.s = love.physics.newEdgeShape(mStartX, mStartX, mEndX, mEndY) // here


Shouldn't be instead walls.s = love.physics.newEdgeShape(mStartX, mStartY, mEndX, mEndY)?
User avatar
melexm
Prole
Posts: 8
Joined: Sat Dec 22, 2012 8:01 pm

Re: X,Y Coordinates not working properly

Post by melexm »

coffee wrote:
melexm wrote: walls.s = love.physics.newEdgeShape(mStartX, mStartX, mEndX, mEndY) // here


Shouldn't be instead walls.s = love.physics.newEdgeShape(mStartX, mStartY, mEndX, mEndY)?


Still not working, it was mispeld because I was trying to play with it.
Any other ideas, I think this has to do with some dx,dy things...
User avatar
vrld
Party member
Posts: 917
Joined: Sun Apr 04, 2010 9:14 pm
Location: Germany
Contact:

Re: X,Y Coordinates not working properly

Post by vrld »

You use mEndX and mEndY but never define them.
I have come here to chew bubblegum and kick ass... and I'm all out of bubblegum.

hump | HC | SUIT | moonshine
User avatar
melexm
Prole
Posts: 8
Joined: Sat Dec 22, 2012 8:01 pm

Re: X,Y Coordinates not working properly

Post by melexm »

vrld wrote:You use mEndX and mEndY but never define them.
OK, it is better now:

Code: Select all

  	walls[i].s = love.physics.newEdgeShape(mStartX, mStartY, x, y)
But still it isn't created at the same point of the mouse.
User avatar
Boolsheet
Inner party member
Posts: 780
Joined: Wed Dec 29, 2010 4:57 am
Location: Switzerland

Re: X,Y Coordinates not working properly

Post by Boolsheet »

The coordinates you set on the shapes are relative to the body origin (also called local coordinates). That means if you create a body at mStartX and attach an EdgeShape that starts at mStartX, the line will start at mStartX*2. Create the body at (0, 0) and the line should be where you expect it to be. You also don't have to create a separate body for each line. It's possible to attach multiple fixtures to one body.
Shallow indentations.
User avatar
melexm
Prole
Posts: 8
Joined: Sat Dec 22, 2012 8:01 pm

Re: X,Y Coordinates not working properly

Post by melexm »

Boolsheet wrote:The coordinates you set on the shapes are relative to the body origin (also called local coordinates). That means if you create a body at mStartX and attach an EdgeShape that starts at mStartX, the line will start at mStartX*2. Create the body at (0, 0) and the line should be where you expect it to be. You also don't have to create a separate body for each line. It's possible to attach multiple fixtures to one body.

Thanks it works!
BTW: Wouldn't fixing shapes to one body makes the collisions not work?
User avatar
Boolsheet
Inner party member
Posts: 780
Joined: Wed Dec 29, 2010 4:57 am
Location: Switzerland

Re: X,Y Coordinates not working properly

Post by Boolsheet »

melexm wrote:BTW: Wouldn't fixing shapes to one body makes the collisions not work?
Uh. I think I don't understand what you are asking.
Shallow indentations.
User avatar
melexm
Prole
Posts: 8
Joined: Sat Dec 22, 2012 8:01 pm

Re: X,Y Coordinates not working properly

Post by melexm »

Boolsheet wrote:
melexm wrote:BTW: Wouldn't fixing shapes to one body makes the collisions not work?
Uh. I think I don't understand what you are asking.
I am creating multiple lines, attaching them to a single body object won't ruin the collisions with them?
User avatar
Boolsheet
Inner party member
Posts: 780
Joined: Wed Dec 29, 2010 4:57 am
Location: Switzerland

Re: X,Y Coordinates not working properly

Post by Boolsheet »

No. That will all still work.
Shallow indentations.
Post Reply

Who is online

Users browsing this forum: Bing [Bot], Google [Bot], Semrush [Bot] and 8 guests