Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/reporting-services/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 在LibGDX中检测圆是与上半部分的矩形相交还是与下半部分的矩形相交_Java_Libgdx - Fatal编程技术网

Java 在LibGDX中检测圆是与上半部分的矩形相交还是与下半部分的矩形相交

Java 在LibGDX中检测圆是与上半部分的矩形相交还是与下半部分的矩形相交,java,libgdx,Java,Libgdx,使用LibGDX,我有一个圆形对象与一个矩形对象碰撞。我使用Libgdx中包含的Intersector类检测此冲突,如下所示: if(Intersector.overlaps(circle, rectangle)){ do something } 这种检测工作得很好,但我想知道是否有办法检测圆是否与矩形的上半部分或下半部分发生碰撞,并根据碰撞发生的位置做出相应的处理 所以可能是 if(Intersector.overlaps(circle, rectangle.get

使用LibGDX,我有一个圆形对象与一个矩形对象碰撞。我使用Libgdx中包含的Intersector类检测此冲突,如下所示:

 if(Intersector.overlaps(circle, rectangle)){
        do something
    }
这种检测工作得很好,但我想知道是否有办法检测圆是否与矩形的上半部分或下半部分发生碰撞,并根据碰撞发生的位置做出相应的处理

所以可能是

if(Intersector.overlaps(circle, rectangle.getHeight() - rectangle.getHeight() / 2)){
    do something
}
但不幸的是,这将返回一个float,intersect类不接受它


任何关于如何实现这一点的想法都将不胜感激。

保留一个可重用的额外矩形实例:

私有最终矩形tmp=新矩形()

当圆与所关心的矩形A相交时,可以将临时矩形设置为矩形A的上半部分,并检查是否存在碰撞。结果告诉您碰撞发生在顶部还是底部。(但如果圆与上半部和下半部相交,则顶部也会发生碰撞,因此请记住这一点。)


工作得很有魅力。谢谢
if(Intersector.overlaps(circle, rectangle)){
    tmp.set(rectangle.x, rectangle.y + rectangle.height/2, rectangle.width, rectangle.height/2);
    if (Intersector.overlaps(circle, tmp){
        //top half (or both top and bottom) hit
    } else {
        //bottom half hit
    }
}