简体   繁体   English

libgdx,如何检查随机生成的actor的冲突?

[英]libgdx, how to check collision of randomly generated actors?

I have two groups of randomly generated actors, one is bullets second is enemies. 我有两组随机生成的演员,一组是子弹,第二组是敌人。 And as of now I have no idea how to check collision of randomly genrated actors and remove the overlaped actors. 到目前为止,我还不知道如何检查随机生成的actor的碰撞并删除重叠的actor。 I'm newby. 我是新人

At least provide some pseudocode! 至少提供一些伪代码! Thanx in advance!!! 提前感谢!!!

  1. Using a physics engine 使用物理引擎

    Libgdx has built-in support for following. Libgdx具有对以下内容的内置支持

    1. Box2d for 2D physics 适用于2D物理的Box2d
    2. Bullet for 3D physics. 3D物理项目符号


    Physics engine can handle collision detection and you can provide callbacks to specify what to do when a collision occurs. 物理引擎可以处理碰撞检测,并且您可以提供回调以指定发生碰撞时的处理方式。

    You can find many tutorials on the internet. 您可以在互联网上找到许多教程。


  1. Implement collision yourself 自己实施碰撞

    It is a bit work but may be suitable for small applications. 这有点工作,但可能适合于小型应用程序。

    1. You will have to perform an^2 intersection check for all objects in each frame. 您将必须对每帧中的所有对象执行^ 2相交检查。
    2. For this, you will have to write intersection test logic for all your shape pairs. 为此,您将必须为所有形状对编写相交测试逻辑。
    3. Then you can deal with detected collisions as per your wish. 然后,您可以根据需要处理检测到的碰撞。

Hope this helps. 希望这可以帮助。
Good luck. 祝好运。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM