Search code examples
c#xnagame-physicsfarseer

Difficulties with Farseer documentation


I tried the "Texture to polygon" example in the Farseer documentation. https://farseerphysics.codeplex.com/documentation But I always get this error message in the following line:

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

No overload for method 'CreatePolygon' takes 4 arguments    

Is there a mistake in the Farseer documentation or what is wrong? What should I change in this line?

In addition, I get these two error messages in the following lines:

_list = BayazitDecomposer.ConvexPartition(verts);
List<Fixture> compund = FixtureFactory.CreateCompoundPolygon(World, _list, 1);

The name 'BayazitDecomposer' does not exist in the current context  
'FarseerPhysics.Factories.FixtureFactory' does not contain a definition for 'CreateCompoundPolygon' 

What is wrong?

I have the following three usings in my code:

using FarseerPhysics.Dynamics;
using FarseerPhysics.Factories;
using FarseerPhysics.Common;

Should I add another using?


Solution

  • I think all of your problems can be summed up by not including the right libraries. I will admit, the FarseerPhysics documentation you linked was not very helpful. You can see in their own source code, for example, that BayazitDecomposer is part of the FarseerPhysics.Common.Decomposition namespace, therefore you'd reference it by saying either

    using FarseerPhysics.Common.Decomposition;
    

    at the top, or just using FarseerPhysics.Common; and in your code:

    Decomposition.BayazitDecomposer() //etc.
    

    I'd recommend looking at other developers' sample code, or diving further into FarseerPhysics' source, in order to see what other libraries you're lacking.

    I notice also in your CreatePolygon case that the method, according to the BodyFactory definition I'm looking at, doesn't even return the Vertices type you believe it does. So in that instance, not only are you possibly missing the library you need, but when you include it, it will say the return type is wrong.

    Perhaps the commenter who suggested that the sample code you're using is based on an older version of Farseer is correct, given these issues.