所以我有一个游戏对象,我通过加载文件中的纹理并转换它来创建一个主体:
Texture2D polygonTexture = Texture2D.FromStream(Game.graphicsDevice, File.OpenRead(filepath));
uint[] data = new uint[polygonTexture.Width * polygonTexture.Height];
polygonTexture.GetData(data);
//convert it to a polygon
Vertices textureVertices = PolygonTools.CreatePolygon(data, polygonTexture.Width, false);
Vector2 centroid = -textureVertices.GetCentroid();
textureVertices.Translate(ref centroid);
Vector2 origin = -centroid;
textureVertices = SimplifyTools.ReduceByDistance(textureVertices, 4f);
List<Vertices> list = BayazitDecomposer.ConvexPartition(textureVertices);
Vector2 vertScale = new Vector2(ConvertUnits.ToSimUnits(1));
foreach (Vertices vertices in list)
{
vertices.Scale(ref vertScale);
}
//creat the body from the verticies
Body compound = BodyFactory.CreateCompoundPolygon(Game.world, list, 1f, BodyType.Dynamic);
compound.BodyType = BodyType.Dynamic;
//set the object's verticies to the polygon and the texture to its image
obj.body = compound;
然后我在抽奖活动中画出这样的画面:
GraphicsDevice.Clear(bgColor);
spriteBatch.Begin(SpriteSortMode.BackToFront, BlendState.AlphaBlend, null, null, null, null, camera2D.get_transformation(graphicsDevice));
obj.body.Position = new Vector2(0, 0);
spriteBatch.Draw(polygonTexture,
ConvertUnits.ToDisplayUnits(obj.body.Position),
null,
obj.tint,
obj.body.Rotation,
Vector2.Zero, 1f,
SpriteEffects.None,
obj.layer);
spriteBatch.End();
图像根本没有显示。我做错了什么?