As the title says, I need to draw a shape/polygon in Farseer using debugview. I have this piece of code which converts a Texture to polygon:

//load texture that will represent the tray
        trayTexture = Content.Load<Texture2D>("tray");

        //Create an array to hold the data from the texture
        uint[] data = new uint[trayTexture.Width * trayTexture.Height];

        //Transfer the texture data to the array

        //Find the vertices that makes up the outline of the shape in the texture
        Vertices verts = PolygonTools.CreatePolygon(data, trayTexture.Width, false);

        //Since it is a concave polygon, we need to partition it into several smaller convex polygons
        _list = BayazitDecomposer.ConvexPartition(verts);
        Vector2 vertScale = new Vector2(ConvertUnits.ToSimUnits(1));
        foreach (Vertices verti in _list)
            verti.Scale(ref vertScale);

        tray = BodyFactory.CreateCompoundPolygon(MyWorld, _list, 10);

Now in DebugView I guess I have to use "DrawShape" method which requires:

DrawShape(Fixture fixture, Transform xf, Color color)

My question is how can I get the variables needed for this method, namely Fixture and Transform?

  • \$\begingroup\$ Have you looked at the sample implementation of the DebugView? It draws shapes perfectly for me. \$\endgroup\$ Aug 5, 2012 at 22:30
  • \$\begingroup\$ You will find Fixtures and Transform in created body: FixtureList and GetTransform \$\endgroup\$
    – szotp
    Feb 1, 2013 at 20:45

1 Answer 1


Have you tried the official documentation?

The getting started section shows how to create a fixture:


Fixture A fixture attaches (fix) the shape to the body so that the centroid of the shape becomes the body’s position. Whenever you move the body, you also move the shape. Once a collision occur to the shape, the force is calculated and applied to the body.

Her is the code to create a World with a single body:

   1:  //Create a World object with zero gravity    
   2:  World world = new World(Vector2.Zero);    

   4:  //We create a body object and make it dynamic (movable)    
   5:  Body myBody = world.CreateBody();    
   6:  myBody.BodyType = BodyType.Dynamic;    
   8:  //We create a circle shape with a radius of 0.5 meters    
   9:  CircleShape circleShape = new CircleShape(0.5f);    
  11:  //We fix the body and shape together using a Fixture object    
  12:  Fixture fixture = myBody.CreateFixture(circleShape);

You can also use the fixture factory

  Fixture fixture = FixtureFactory.CreateCircle(_world, 0.5f, 5, new Vector2(10, 0));

You can probably create a default transform (that doesn't transform anything) using:

Transfrom transform;

Note that you can also use the Box2D manuals, since Farseer offers the same features.

  • \$\begingroup\$ Hi Roy. Farseer documentation is just obsolete since it's made for version 2.X. FixtureFactory have been removed in Version 3, and another problem is I don't want a circle shape! I want my own custom shape which is made from the texture. \$\endgroup\$ Apr 7, 2012 at 16:49
  • \$\begingroup\$ It's true that the V3 docs are way basic, but I pulled this from them. I haven't installed Farseer, but have you looked at the other methods of the FixtureFactory, I'm sure there are more options :). \$\endgroup\$
    – Roy T.
    Apr 7, 2012 at 18:31
  • \$\begingroup\$ May I ask why you rolled back the edit? \$\endgroup\$
    – Vaillancourt
    May 14, 2021 at 16:04
  • \$\begingroup\$ @Vaillancourt sure, the question is about Farseer, I know Velcro is the sucessor but it was never finished and has a different API so answers for Farseer are not applicable to Velcro. :) \$\endgroup\$
    – Roy T.
    May 17, 2021 at 14:05
  • 1
    \$\begingroup\$ Okay; the update to the link has been motivated by the shut down of CodePlex. So in two months from now, the link in the answer will have rotten. (The link is already outdated because it does not link to the quote.) You might want to edit the answer and remove the link, and reword the post to make keep it "whole". \$\endgroup\$
    – Vaillancourt
    May 17, 2021 at 14:22

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .