# Rotating an object about a point (2D) using box2d

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

• Possible duplicate: gamedev.stackexchange.com/questions/3758/box-2d-set-origin – MichaelHouse Aug 11 '13 at 17:47
• yea. i read that post, but setasbox don't work in changing the pivot point. needed help on setasbox and setasorientedbox – noob Aug 15 '13 at 15:49
• Why do you need box2d for this? – 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

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;