获取多边形形状体的顶点列表 [英] Get vertice list of a polygon shape body
本文介绍了获取多边形形状体的顶点列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在libgdx中获取特定多边形体的顶点列表?
How do you get a list of vertices for a specific polygon body in libgdx?
像这样:
public Array<Vector2> getVerts(Body body){
Array<Vector2>verts = null;
// can't find how to look them up properly anywhere
return verts;
}
谢谢!
推荐答案
基于@James Webster的代码:
Based on @James Webster's code:
Array<Vector2> verts = new Array<Vector2>();
Fixture f = body.getFixtureList().get(0);
PolygonShape s = f.shape;
// this is needed to temporarily keep the vertex, getVertex is a void method
Vector2 tmp = new Vector2();
for (int i = 0; i < s.getVertexCount(); i++) {
// fill tmp with the vertex
s.getVertex(i, tmp));
verts.add(new Vector2(tmp));
}
这篇关于获取多边形形状体的顶点列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文