.position.Set() vs .SetPosition()

Discuss issues specific the Javascript port of Box2D
Kott
Posts: 23
Joined: Sun Jun 08, 2014 11:24 am

.position.Set() vs .SetPosition()

Postby Kott » Thu Jul 03, 2014 9:03 am

I understand that those 2 functions are taken from 2 different classes and that they're used for different tasks.
With .SetPosition() you define at which point you want a body to appear in your world, if x=0 and y=0 in .SetPosition() your body will appear in your top-left corner.
What .position.Set() actually do? what "specify the position of the body's origin" mean?
how can you see where a body's origin is? I say that because if x and y values are entered in .position.Set() the body's position won't change because you do that with .SetPosition() but supposedly it's origin position is changed...

irresistible force
Posts: 1991
Joined: Tue Jun 24, 2008 8:25 pm
Location: Tokyo
Contact:

Re: .position.Set() vs .SetPosition()

Postby irresistible force » Thu Jul 03, 2014 3:28 pm

I believe the .position.Set() one is part of the b2BodyDef class? That is what you use when first defining the body to create it. It's not really necessary since you can do the .SetPosition() on the body after it's created.

Kott
Posts: 23
Joined: Sun Jun 08, 2014 11:24 am

Re: .position.Set() vs .SetPosition()

Postby Kott » Fri Jul 04, 2014 3:05 am

.SetPosition() function is from b2Body class, it's definition from the manual is the following: Set the world body origin position. Plain and simple.
On the other hand .position.Set() function is from b2BodyDef class, it's definition from the manual it this: The world position of the body. Avoid creating bodies at the origin since this can lead to many overlapping shapes.
The reason i get confused with .position.Set() is because it says "lead to overlapping shapes" so it also has something to do with shapes getting attached to the bodies.
Do you like, set the shape origin on the body with .position.Set()? Or is it something else?

irresistible force
Posts: 1991
Joined: Tue Jun 24, 2008 8:25 pm
Location: Tokyo
Contact:

Re: .position.Set() vs .SetPosition()

Postby irresistible force » Fri Jul 04, 2014 6:23 am

I believe the "world position of the body" and "world body origin position" are the same thing.
In any case, I would think a little experimentation should pretty quickly let you see if I'm wrong...


Return to “Javascript”



Who is online

Users browsing this forum: No registered users and 1 guest