我去的论坛上有人说我不应该使用Rectangle.intersects进行碰撞检测,而应该使用以下算法:

boolean rectangleIntersects(float rect1x, float rect1y, float rect1w,
                            float rect1h, float rect2x, float rect2y,
                            float rect2w, float rect2h)
{
    return (rect1x + rect1w >= rect2x &&
            rect1y + rect1h >= rect2y &&
            rect1x <= rect2x + rect2w &&
            rect1y <= rect2y + rect2h);
}


但是Rectangle.intersects算法是否有所不同,并且比这更好?

最佳答案

Rectangle.intersects is basically the same,不同之处在于算法使用的是float而不是double,并且包括边界的相等条件。

关于java - 交集算法与Rectangle.intersects(Rectangle r)之间的区别,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/4270572/

10-10 13:54