java - 获取多边形体的顶点列表

标签 java libgdx

如何在 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/

相关文章:

java - 如何将结果集对象与字符串进行比较?

java - 使用 java 流查找第一个免费的 "index"

java - 在 Spring data mongodb 中从同一个 POJO 创建两个集合

java - 使用JAVA打开CSV文件(使用JXL库)

java - LibGDX GDX-Pay 崩溃

java - 如何使用 libgdx 绘制边界线内的图像部分?

java - libgdx 背景纹理区域重复

java - Java EE 到底是什么?

java - Ray 和 intersectRayTriangle 如何工作?

libgdx - 在按钮-LibGdx 上使用操作