Anchor Point / Origin Point

Here's the place to get help and discuss features. The focus is on the C++ version, but generic questions are welcome.
shivaz
Posts: 3
Joined: Mon Aug 24, 2009 11:52 pm

Anchor Point / Origin Point

Postby shivaz » Mon Aug 24, 2009 11:58 pm

Dear All

I have been working on implementing Box 2d into my Cocos2d-iphone game - and have hit one minor snag.
My sprites have an anchor point that is at 75% of y. So instead of being dead center, it is centered on the X - and 3/4s up on the Y.
So when you try to line the sprite up with the body/shape - it is offset.
With the Chipmunk code I was using, allowed me to offset the body/shape so that it lined up perfectly - and I could then move it and rotate it no worries.

Have I missed a way of setting the point of origin or anchor point somewhere?
Do I have to roll some maths code to calculate the offset (taking into account the rotation) - not sure if I still have enough skills!

Any ideas.

Thanks

Justin

Erin Catto
Site Admin
Posts: 2948
Joined: Thu Sep 06, 2007 12:34 am

Re: Anchor Point / Origin Point

Postby Erin Catto » Tue Aug 25, 2009 12:11 am

The body origin can be where ever you like. Shapes can be offset from that.

shivaz
Posts: 3
Joined: Mon Aug 24, 2009 11:52 pm

Re: Anchor Point / Origin Point

Postby shivaz » Tue Aug 25, 2009 4:54 am

Thanks Erin - will check that out.

Justin

shivaz
Posts: 3
Joined: Mon Aug 24, 2009 11:52 pm

Re: Anchor Point / Origin Point

Postby shivaz » Tue Aug 25, 2009 6:20 am

For anyone who is interested, it is quite simple to offset the position of the shape from the position of the body.

In the case of a Polygon shape, the code is here:
http://www.box2d.org/manual.html#d0e910

In summary the line below, creates a box shape - .6 wide, 2 high, with its center lined up .55 below the center of the body.
boxDef.SetAsBox(0.3f,1.0f,b2Vec2(0.0f,-0.55F), 0.0F);

Justin


Return to “General Discussion”



Who is online

Users browsing this forum: Bing [Bot] and 4 guests