如何在 libgdx 中获取特定多边形主体的顶点列表?
像这样:
public Array<Vector2> getVerts(Body body){
Array<Vector2>verts = null;
// can't find how to look them up properly anywhere
return verts;
}
谢谢!
最佳答案
我没有使用过 LibGDX,但我使用过 Box2D 并查看了 API,我建议:
//Assuming only 1 fixture per body and a polygon shape
Array<Vector2>verts = new Array<Vector2>();
Fixture f = body.getFixtureList().get(0);
PolygonShape s = f.shape;
for (int i = 0; i < s.getVertexCount(); i++)
{
verts.add(s.getVertex(i, /*I couldn't figure out what this param is supposed to be*/));
}
这是在没有 IDE 的情况下输入的,注意明显的错误!我也好久没搞Java了。
关于java - 获取多边形体的顶点列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20098779/