[英]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: 所以在步骤中你:
Polygon
将该数据反序列化为LibGDX Polygon
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.