0
\$\begingroup\$

i just started developing using box2d on flixel and i realise the pivot point of the rotation of an object in box2d is set to the center of an object.

i had read on forums and i found out that SetAsBox can change the pivot point of the object, however, i cannot seem to get it work to rotate about a point.

what i would like to achieve is to rotate an object about a point like earth revolving around the sun. any one can help me with it? really thanks a lot and sorry for the bad english

\$\endgroup\$
3
  • \$\begingroup\$ Possible duplicate: gamedev.stackexchange.com/questions/3758/box-2d-set-origin \$\endgroup\$
    – House
    Commented Aug 11, 2013 at 17:47
  • \$\begingroup\$ yea. i read that post, but setasbox don't work in changing the pivot point. needed help on setasbox and setasorientedbox \$\endgroup\$
    – noob
    Commented Aug 15, 2013 at 15:49
  • \$\begingroup\$ Why do you need box2d for this? \$\endgroup\$
    – bummzack
    Commented Oct 21, 2013 at 8:43

1 Answer 1

1
\$\begingroup\$

You could create a Sprite subclass that features a pivot point and uses transformation matrix to update position, scaling and rotation. A nice example with source code can be found here : http://jamesvango.co.uk/blog/?p=136

Another lazy way to get around, is adding your sprite in a container sprite, then move it so it's center is alligned with the parent's top left corner

containerSprite.addChild(child);
child.x = -child.width/2;
child.y = -child.height/2;

and update the containerSprite's position and rotation

containerSprite.x = body.GetPosition().x * worldScale;
containerSprite.y = body.GetPosition().y * worldScale;              
containerSprite.rotation = body.GetAngle() * 180 / Math.PI;
\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .