Java/libGDX - 如何检查多边形与矩形或圆形的碰撞

2022-01-12 00:00:00 polygon collision-detection java libgdx

我是 libGDX 的新手,据我所知,Intersector 类具有 Rectangle/Rectangle、Circle/Circle、Circle/Rectangle 和 Polygon/Polygon 的重叠方法,但由于某种原因,它似乎没有检查多边形/矩形或多边形/圆形的任何方法.

I'm new to libGDX and from what I can tell the Intersector class has overlap methods for Rectangle/Rectangle, Circle/Circle, Circle/Rectangle, and Polygon/Polygon, but for some reason it doesn't seem to have any methods for checking Polygon/Rectangle or Polygon/Circle.

有没有推荐的方法来检查多边形和矩形/圆之间的碰撞?

Is there a recommended way to check for collision between polygon and rect/circle?

另外,是否有某些原因将其排除在 Intersector 类之外?(即,我应该避免它吗?如果是,推荐的替代方法是什么?)

Also, is there some reason why this has been left out of the Intersector class? (ie, should I avoid it? If so, what's the recommended alternative?)

推荐答案

处理这些碰撞的最佳方法是使用像 Box2D 这样的物理引擎,它已经与 Libgdx 打包在一起.当 Box2D 中发生碰撞时,会触发一个事件,您可以轻松处理该事件.所以你应该看看这里.

The best way to handle those collisions would be to use a physics engine like Box2D which already comes packed with Libgdx. When a collision occurs in Box2D a event gets fired and you can easly handle that event. So you should probably take a look here.

当然还有其他处理碰撞检测的方法.只需一点点数学知识,您可能就可以自己弄清楚您需要什么,而且 Box2D 还提供了许多其他可以让您受益的功能.

Of course there are other ways of dealing of dealing with collision detection. With a little bit of maths you could probaly figure out just what you need on your own, also Box2D comes with alot of other features that will benefit you.

相关文章