This project has moved and is read-only. For the latest updates, please go here.

Pixels, Meters, Body Shape

Nov 4, 2011 at 1:34 PM

hi all,

I am new to Farseer, and I am having trouble alligning my body shape with the textures drawn on screen.

Before I have use the Physics Helper library ( and Blend to make my WP7 games here:

Now I am trying to recreate the games in XNA so that I can use MonoGame ( to port them to Android et al.

I have four buffers that make up the table, and 13 balls inside that table, but of course the body shapes are not aligned, so the balls are colliding with shapes that are out of proportion and in the wrong place.

Here is the code for one of the buffer bodies:

            bufferBody[0] = BodyFactory.CreateRectangle(world, 25, 500, 4);
            bufferBody[0].Position = new Vector2(0, 50);
            bufferBody[0].IsStatic = true;
And here is the draw code for a buffer texture:
            spriteBatch.Draw(buffers[0], new Rectangle(0, 50, 25, 500), Color.White);
For a disk body:
            body = BodyFactory.CreateCircle(table.World, 12.5f, 1);
            body.BodyType = BodyType.Dynamic;
            body.Position = pos;
And the texture:
            spriteBatch.Draw(texture, new Rectangle((int)pos.X, (int)pos.Y, 25, 25), colour);

My game is very simple, and I am not using a projection or view Matrices, just a very simple 0,0 at top left.
The buffers are 500px,25px horizontal (25px,500px vertical), and the disks are 25px,25px.