Java / libGDX - 如何检查多边形与Rectangle或Circle的碰撞 [英] Java/libGDX - how to check Polygon collision with Rectangle or Circle

查看:260
本文介绍了Java / libGDX - 如何检查多边形与Rectangle或Circle的碰撞的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新来libGDX,从我可以告诉部门间类有重叠的矩形/矩形,圆形/圆,圆/矩形和多边形/多边形的方法,但由于某种原因,它似乎并不有检查多边形/矩形或多边形/圆形的任何方法。

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.

这篇关于Java / libGDX - 如何检查多边形与Rectangle或Circle的碰撞的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆