当我想在Farseer中创建多边形时,我总是收到很多错误消息。
'FarseerPhysics.Common.Vertices'不包含的定义 'CreatePolygon''FarseerPhysics.Factories.BodyFactory'没有 包含'Instance'的定义'physicsSimulator'的名称 在当前上下文中不存在名称'triangleGeomtry'不存在 存在于当前上下文中名称'GeomFactory'不存在于 当前上下文名称'physicsSimulator'不存在于 当前背景
有什么问题? 如何在Farseer中创建多边形?
triangleSprite = Content.Load<Texture2D>("triangle"); // Load the Sprite
data = new uint[triangleSprite.Width * triangleSprite.Height];
triangleSprite.GetData(data);
verts = Vertices.CreatePolygon(data, triangleSprite.Width, triangleSprite.Height);
polygonOrigin = verts.GetCentroid();
triangleBody = BodyFactory.Instance.CreatePolygonBody(physicsSimulator, verts, 3);
triangleBody.Position = new Vector2(400, 600);
triangleGeomtry = GeomFactory.Instance.CreatePolygonGeom(physicsSimulator, triangleBody, verts, 0);
答案 0 :(得分:0)
继承人我是怎么做的..使用XNA 4和Farseer 3.3.1
//List of vectors defining my custom poly
Vector2[] vlist =
{
ConvertUnits.ToSimUnits(new Vector2(25,0))
,ConvertUnits.ToSimUnits(new Vector2(15,25))
,ConvertUnits.ToSimUnits(new Vector2(-15,25))
,ConvertUnits.ToSimUnits(new Vector2(-25,0))
,ConvertUnits.ToSimUnits(new Vector2(-15,-10))
,ConvertUnits.ToSimUnits(new Vector2(15,-10))
};
//get farseer 'vertices' from vectors
Vertices _shapevertices = new Vertices(vlist);
//feed vertices array to BodyFactory.CreatePolygon to get a new farseer polygonal body
_newBody = BodyFactory.CreatePolygon(_world, _shapevertices, _stats.Density);
我自己定义了这个形状,但我知道farseer包含的工具会根据精灵为你提供'顶点'对象,如果你想这样做的话。
纹理到多边形部分here贯穿了如何做到这一点。