Rectangle Body/Geometry drawing

Topics: Developer Forum, User Forum
Oct 16, 2007 at 6:48 PM
I want to have arbitrary rectangular bodies in my scene, but I'm having trouble drawing them correctly. Basically, I have a 512x512 sprite for the platform, and up until this point I have been using spriteBatch.Draw with a destination rectangle (this is with static rectangular platforms). I then tried to set the platforms to dynamic, and use the spriteBatch.Draw method with destination rectangle and rotation, but this didn't work at all. The platform seems to be off center at certain angles, but fine at other angles...

Basically, I'd like to fill in the blanks in this code (or something that works if that isn't the correct form of Draw I need to use):

static void DrawRectangularBody(Body body, float width, float height, SpriteBatch spriteBatch, Texture2D tex, Color color)
{
Vector2 middle = new Vector2(width / 2, height / 2);
Rectangle destinationRect = _____; // (body.Position
Rectangle sourceRect = ____; // null?
Vector2 origin = ____;

spriteBatch.Draw(tex, destinationRect, sourceRect,
color, body.Rotation, origin, SpriteEffects.None, layerDepth);
}