love.physics.newBody

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
ghostrunners
Prole
Posts: 8
Joined: Fri Jan 27, 2012 3:40 pm
Location: Georgia

love.physics.newBody

Post 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!
"Imagination is more important that knowledge...." - Einstein
User avatar
tentus
Inner party member
Posts: 1060
Joined: Sun Oct 31, 2010 7:56 pm
Location: Appalachia
Contact:

Re: love.physics.newBody

Post 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.
Kurosuke needs beta testers
ghostrunners
Prole
Posts: 8
Joined: Fri Jan 27, 2012 3:40 pm
Location: Georgia

Re: love.physics.newBody

Post 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!
"Imagination is more important that knowledge...." - Einstein
User avatar
tentus
Inner party member
Posts: 1060
Joined: Sun Oct 31, 2010 7:56 pm
Location: Appalachia
Contact:

Re: love.physics.newBody

Post 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. :)
Kurosuke needs beta testers
Post Reply

Who is online

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