使用Farseer文档的困难

本文关键字:文档 Farseer 使用 | 更新日期: 2023-09-27 18:14:32

我尝试了Farseer文档中的"Texture to polygon"示例。https://farseerphysics.codeplex.com/documentation但是我总是在下面一行得到这个错误信息:

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

是有一个错误在Farseer文档或什么是错误的?我在这条线上应该换什么?

此外,我在以下行中得到这两个错误消息:

_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' 

怎么了?

在我的代码中有以下三种用法:

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

我应该添加另一个用法吗?

使用Farseer文档的困难

我认为你所有的问题都可以归结为没有包含正确的库。我承认,你所链接的FarseerPhysics文档并不是很有帮助。例如,您可以在他们自己的源代码中看到,BayazitDecomposer是FarseerPhysics.Common.Decomposition名称空间的一部分,因此您可以通过

引用它
using FarseerPhysics.Common.Decomposition;

在顶部,或者只是using FarseerPhysics.Common;,在你的代码中:

Decomposition.BayazitDecomposer() //etc.

我建议你看看其他开发者的示例代码,或者深入研究FarseerPhysics的源代码,看看你还缺少哪些库。

我还注意到在您的CreatePolygon情况下,该方法,根据我正在查看的BodyFactory定义,甚至不返回您认为的Vertices类型。因此,在这种情况下,您不仅可能缺少所需的库,而且当您包含它时,它会提示返回类型错误。

考虑到这些问题,也许建议您使用的示例代码是基于旧版本的Farseer的评论者是正确的。

当你下载文件Farseer Physics Engine 3.3.1 Samples XNA!高级演示1有一个"纹理到多边形"的例子

这个页面的文档已经过时了。