Page 1 of 1

love.physics.newBody

Posted: Tue Jan 31, 2012 1:53 pm
by ghostrunners
Hi, I'm new to love2d, and just can't wrap my head around this statement in the physics tutorial - https://love2d.org/wiki/Tutorial:Physics ... "the shape anchors to the body from its center".

The statement in question =

Code: Select all

objects.ground.body = love.physics.newBody(world, 650/2, 625, 0, 0)
Why does the X position of the body have to be divided by 2? If we should anchor the body from its center, are there situations where we may NOT want to anchor body from its center? Thanks in advance, great engine, I'm loving it!

Re: love.physics.newBody

Posted: Tue Jan 31, 2012 3:23 pm
by tentus
The x position is divided by two because the author wanted it to be in the middle of the screen. It could have been anything. We could have put it at position 0 and just made it wider and the tutorial would have still worked.

To answer your second question, a body's center will always be its center, as far as I know. Note that we can attach shapes to bodies in positions other than the center, if that's what you were asking.

Re: love.physics.newBody

Posted: Tue Jan 31, 2012 3:53 pm
by ghostrunners
Thanks for the quick response - so when I change the x position of the body to be 800 (default dimensions), not 800/2, the center of the body moves to position 800 on the x-axis? Thereby shifting the display of the shape to the far right, since only half of the 800 width shape is being displayed within that world? If thats the case, then I got it! - you're awesome! I love this community because of their great way of explaining things!

Re: love.physics.newBody

Posted: Tue Jan 31, 2012 3:55 pm
by tentus
ghostrunners wrote:Thanks for the quick response - so when I change the x position of the body to be 800 (default dimensions), not 800/2, the center of the body moves to position 800 on the x-axis? Thereby shifting the display of the shape to the far right, since only half of the 800 width shape is being displayed within that world? If thats the case, then I got it! - you're awesome! I love this community because of their great way of explaining things!
Yes. :)