Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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
1  
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
1  
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
add comment

1 Answer

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.
        polygonTexture.GetData(data);

        //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);

    }

-http://stackoverflow.com/questions/7189691/create-a-body-of-a-irregular-2d-sprite-in-farseer

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: http://farseerphysics.codeplex.com/documentation

share|improve this answer
add comment

Your Answer

 
discard

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.