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

2023-03-01Java开发问题
3

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

The End

相关推荐

如何使用 JAVA 向 COM PORT 发送数据?
How to send data to COM PORT using JAVA?(如何使用 JAVA 向 COM PORT 发送数据?)...
2024-08-25 Java开发问题
21

如何使报表页面方向更改为“rtl"?
How to make a report page direction to change to quot;rtlquot;?(如何使报表页面方向更改为“rtl?)...
2024-08-25 Java开发问题
19

在 Eclipse 项目中使用西里尔文 .properties 文件
Use cyrillic .properties file in eclipse project(在 Eclipse 项目中使用西里尔文 .properties 文件)...
2024-08-25 Java开发问题
18

有没有办法在 Java 中检测 RTL 语言?
Is there any way to detect an RTL language in Java?(有没有办法在 Java 中检测 RTL 语言?)...
2024-08-25 Java开发问题
11

如何在 Java 中从 DB 加载资源包消息?
How to load resource bundle messages from DB in Java?(如何在 Java 中从 DB 加载资源包消息?)...
2024-08-25 Java开发问题
13

如何更改 Java 中的默认语言环境设置以使其保持一致?
How do I change the default locale settings in Java to make them consistent?(如何更改 Java 中的默认语言环境设置以使其保持一致?)...
2024-08-25 Java开发问题
13