简体   繁体   English

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

[英]How to create a polygon on a texture libGDX

I want to create a polygon by cutting the transparent area from a texture. 我想通过从纹理中剪切透明区域来创建多边形。 I wrote a program which detects collision between 2 objects. 我写了一个程序来检测2个对象之间的碰撞。 But the collision is detected before they are in collision. 但是在碰撞之前检测到碰撞。 That's how it looks: http://imgur.com/a/dFmXI 这就是它的外观: http//imgur.com/a/dFmXI

This is the code: https://hastebin.com/bebusadiku.java I thought to cut the texture and create a polygon based on the cutted texture and then detect the collision using an Intersector method but I have no idea how to specify the vertexes of the polygon. 这是代码: https//hastebin.com/bebusadiku.java我想切割纹理并根据切割纹理创建多边形,然后使用Intersector方法检测碰撞,但我不知道如何指定顶点多边形

I tried to follow this but there's no explain how to detect the vertexes : https://gamedev.stackexchange.com/questions/114228/how-to-detect-collision-only-in-non-transparent-texture 我试图遵循这个但是没有解释如何检测顶点: https//gamedev.stackexchange.com/questions/114228/how-to-detect-collision-only-in-non-transparent-texture

Thanks for help 感谢帮助

I used 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. 我相信Box2D它可以在“盒子”之外工作,但Box2D占用了大量空间,如果你不使用实际物理,这是不必要的。 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 . 但是,此工具生成JSON格式的多边形坐标,并且将其反序列化为Polygon对象并与Intersector实现进行冲突并不困难。 So in steps you: 所以在步骤中你:

  • Create a shape for your images using the shape editor tool . 使用形状编辑器工具为图像创建形状。
  • Export that to JSON with the tool. 使用该工具将其导出到JSON。
  • Deserialize that data into a LibGDX Polygon 将该数据反序列化为LibGDX Polygon
  • Move, scale and attach it properly to your image so it's synchronized. 移动,缩放并将其正确附加到图像,使其同步。
  • First check collision on a basic rectangle vs rectangle. 首先检查基本矩形与矩形的碰撞。
  • If there is a basic collision do a more detailed collision detection with Intersector . 如果存在基本碰撞,请使用Intersector进行更详细的碰撞检测。

The tool exports a lot of redundant data, if you get yourself familiar with the format it exports you can get rid of all data except the polygon/vertices data. 该工具导出大量冗余数据,如果您熟悉它导出的格式,您可以除去多边形/顶点数据之外的所有数据。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM