如何在纹理上创建多边形 libGDX

How to create a polygon on a texture libGDX

我想通过从纹理中切割透明区域来创建多边形。 我写了一个程序来检测两个物体之间的碰撞。 但是在它们发生碰撞之前就检测到碰撞。 看起来是这样的:http://imgur.com/a/dFmXI

这是代码:https://hastebin.com/bebusadiku.java 我想切割纹理并根据切割纹理创建多边形,然后使用 Intersector 方法检测碰撞,但我不知道如何指定多边形的顶点。

我试图遵循这个,但没有解释如何检测顶点: https://gamedev.stackexchange.com/questions/114228/how-to-detect-collision-only-in-non-transparent-texture

感谢帮助

我用了this polygonal shape editor to create more complex shapes for checking collisions. I believe with Box2D it works out of the "box" but Box2D takes a lot of space and that is unnecessary if you don't use the actual physics. However, this tool generates JSON formatted polygonal coordinates and it's not that hard to deserialize that back into Polygon objects and do collision with the Intersector implementation。所以在步骤中你:

  • 使用 shape editor tool 为您的图像创建形状。
  • 使用工具将其导出到 JSON。
  • 将该数据反序列化为 LibGDX Polygon
  • 移动、缩放并将其正确附加到您的图像以使其同步。
  • 首先检查基本矩形与矩形的碰撞。
  • 如果存在基本碰撞,请使用 Intersector 进行更详细的碰撞检测。

该工具导出大量冗余数据,如果您熟悉它导出的格式,您可以删除除 polygon/vertices 数据之外的所有数据。