gpt4 book ai didi

xna - 在 Farseer 中创建不规则 2D Sprite 的主体

转载 作者:行者123 更新时间:2023-12-04 20:20:04 24 4
gpt4 key购买 nike

我正在尝试创建一个不规则 2D Sprite Farseer 3.3.1 的主体。可以使用 BodyFactory.CreateCompoundPolygon 方法完成吗?

最佳答案

这是我的一个项目中的一种方法。它有点特定于我的架构,但应该对自己有用。

需要考虑的一件事是缩放。您最好将其替换为我相信您熟悉的 ConvertUnits.ToSimUnits 等。

       public static Body CreateBodyFromImage(Game game, World world, string textureName)
{
//Load the passed texture.
Texture2D polygonTexture = game.Content.Load<Texture2D>(textureName);

//Use an array to hold the textures data.
uint[] data = new uint[polygonTexture.Width * polygonTexture.Height];

//Transfer the texture data into the array.
polygonTexture.GetData(data);

//Find the verticals that make up the outline of the passed texture shape.
Vertices vertices = PolygonTools.CreatePolygon(data, polygonTexture.Width);

//For now we need to scale the vertices (result is in pixels, we use meters)
Vector2 scale = new Vector2(0.07f, 0.07f);
vertices.Scale(ref scale);

//Partition the concave polygon into a convex one.
var decomposedVertices = BayazitDecomposer.ConvexPartition(vertices);

//Create a single body, that has multiple fixtures to the polygon shapes.
return BodyFactory.CreateCompoundPolygon(world, decomposedVertices, 1f);

}

关于xna - 在 Farseer 中创建不规则 2D Sprite 的主体,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7189691/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com