Box2D Forums

It is currently Fri Apr 25, 2014 12:33 am

All times are UTC - 8 hours [ DST ]




Post new topic Reply to topic  [ 4 posts ] 
Author Message
PostPosted: Mon Aug 24, 2009 11:58 pm 
Offline

Joined: Mon Aug 24, 2009 11:52 pm
Posts: 3
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


Top
 Profile  
 
PostPosted: Tue Aug 25, 2009 12:11 am 
Offline
Site Admin

Joined: Thu Sep 06, 2007 12:34 am
Posts: 2946
The body origin can be where ever you like. Shapes can be offset from that.


Top
 Profile  
 
PostPosted: Tue Aug 25, 2009 4:54 am 
Offline

Joined: Mon Aug 24, 2009 11:52 pm
Posts: 3
Thanks Erin - will check that out.

Justin


Top
 Profile  
 
PostPosted: Tue Aug 25, 2009 6:20 am 
Offline

Joined: Mon Aug 24, 2009 11:52 pm
Posts: 3
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


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC - 8 hours [ DST ]


Who is online

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


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group