Java/libGDX - how to check Polygon collision with Rectangle or Circle(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.
这篇关于Java/libGDX - 如何检查多边形与矩形或圆形的碰撞的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Java/libGDX - 如何检查多边形与矩形或圆形的碰撞


- GC_FOR_ALLOC 是否更“严重"?在调查内存使用情况时? 2022-01-01
- 如何指定 CORS 的响应标头? 2022-01-01
- 在 Java 中,如何将 String 转换为 char 或将 char 转换 2022-01-01
- 获取数字的最后一位 2022-01-01
- Eclipse 的最佳 XML 编辑器 2022-01-01
- java.lang.IllegalStateException:Bean 名称“类别"的 BindingResult 和普通目标对象都不能用作请求属性 2022-01-01
- 转换 ldap 日期 2022-01-01
- 将 Java Swing 桌面应用程序国际化的最佳实践是什么? 2022-01-01
- 如何使 JFrame 背景和 JPanel 透明且仅显示图像 2022-01-01
- 未找到/usr/local/lib 中的库 2022-01-01