## X,Y Coordinates not working properly

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
melexm
Prole
Posts: 8
Joined: Sat Dec 22, 2012 8:01 pm

### X,Y Coordinates not working properly

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.

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

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)?
melexm
Prole
Posts: 8
Joined: Sat Dec 22, 2012 8:01 pm

### Re: X,Y Coordinates not working properly

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...
vrld
Party member
Posts: 917
Joined: Sun Apr 04, 2010 9:14 pm
Location: Germany
Contact:

### Re: X,Y Coordinates not working properly

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

### Re: X,Y Coordinates not working properly

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.
Boolsheet
Inner party member
Posts: 780
Joined: Wed Dec 29, 2010 4:57 am
Location: Switzerland

### Re: X,Y Coordinates not working properly

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

### Re: X,Y Coordinates not working properly

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?
Boolsheet
Inner party member
Posts: 780
Joined: Wed Dec 29, 2010 4:57 am
Location: Switzerland

### Re: X,Y Coordinates not working properly

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

### Re: X,Y Coordinates not working properly

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?
Boolsheet
Inner party member
Posts: 780
Joined: Wed Dec 29, 2010 4:57 am
Location: Switzerland

### Re: X,Y Coordinates not working properly

No. That will all still work.
Shallow indentations.

### Who is online

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