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

  • \$\begingroup\$ Possible duplicate: gamedev.stackexchange.com/questions/3758/box-2d-set-origin \$\endgroup\$ – MichaelHouse Aug 11 '13 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 Aug 15 '13 at 15:49
  • \$\begingroup\$ Why do you need box2d for this? \$\endgroup\$ – bummzack Oct 21 '13 at 8:43

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

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;
|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.