当我尝试将灯具连接到主体时,我总是在此行中收到此错误消息。
Fixture Newfixture = FixtureFactory.AttachCompoundPolygon(list, 1.0f, TestBody);
无法将类型'System.Collections.Generic.List'隐式转换为'FarseerPhysics.Dynamics.Fixture'
如何创建灯具并将其贴在车身上?是否可以将多个固定装置连接到身体上?
我的其余代码:
List<Vertices> list = new List<Vertices>();
Vector2 _origin;
float _scale;
uint[] data = new uint[Sprite.Width * Sprite.Height];
Sprite.GetData(data);
Vertices textureVertices = PolygonTools.CreatePolygon(data, Sprite.Width, false);
Vector2 centroid = -textureVertices.GetCentroid();
textureVertices.Translate(ref centroid);
_origin = -centroid;
textureVertices = SimplifyTools.ReduceByDistance(textureVertices, 4f);
list = Triangulate.ConvexPartition(textureVertices, TriangulationAlgorithm.Bayazit);
_scale = 1f;
Vector2 vertScale = new Vector2(ConvertUnits.ToSimUnits(1)) * _scale;
foreach (Vertices vertices in list)
{
vertices.Scale(ref vertScale);
}
答案 0 :(得分:0)
Fixture Newfixture = FixtureFactory.AttachCompoundPolygon(list, 1.0f, TestBody);
这行代码返回List<Fixture>
这是FixtureFactory源代码中的方法签名。
public static List<Fixture> AttachCompoundPolygon(List<Vertices> list, float density, Body body)
所以你回来了List<Fixture>
。如果你想获得该列表中的第一个项目(可能是这种情况,因为你假设那里只有一个),那么
Fixture Newfixture = FixtureFactory.AttachCompoundPolygon(list, 1.0f, TestBody).First();