Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am making a 2D XNA Game, using Farseer Physics for collisions.

I need collisions to be resolved against the actual shape of the sprite image, ignoring transparent pixels, rather than against the edge of the bounding rectangle.

share|improve this question
Farseer is a physics engine and has no internal rendering capability itself. I am struggling to determine what you are actually asking here? – Andrew Russell Jan 31 '13 at 12:07
I was bold and massively reworded the question. I hope this is an accurate translation of the main question; feel free to revert if I have changed the meaning. I also removed the other question about compiling a project into a DLL. You can ask that as a separate question. – Jimmy Feb 1 '13 at 0:22
up vote 2 down vote accepted

I am not sure what you mean by rendering... I think you meant how you would create a specific shape using Farseer Physics. Using this code:

   public static Body CreateBodyFromImage(Game game, World world, string textureName)
        //Load the passed texture.
        Texture2D polygonTexture = game.Content.Load<Texture2D>(textureName);

        //Use an array to hold the textures data.
        uint[] data = new uint[polygonTexture.Width * polygonTexture.Height];

        //Transfer the texture data into the array.

        //Find the verticals that make up the outline of the passed texture shape.
        Vertices vertices = PolygonTools.CreatePolygon(data, polygonTexture.Width);

        //For now we need to scale the vertices (result is in pixels, we use meters)
        Vector2 scale = new Vector2(0.07f, 0.07f);
        vertices.Scale(ref scale);

        //Partition the concave polygon into a convex one.
        var decomposedVertices = BayazitDecomposer.ConvexPartition(vertices);

        //Create a single body, that has multiple fixtures to the polygon shapes.
        return BodyFactory.CreateCompoundPolygon(world, decomposedVertices, 1f);



You will be able to create a custom Body that has the shape of your desired sprite(you can see this in Farseer's Debug View). If you let Farseer handle the collisions then you should get the desired collision as you have described above.

I also recommend taking a look at their documentation:

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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