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

时间:2023-03-01
本文介绍了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 - 如何检查多边形与矩形或圆形的碰撞的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

上一篇:如何在 Libgdx 中支持 OpenGL ES GL10、GL11 和 GL20? 下一篇:如何通过代理设置 libGDX 项目

相关文章