我去的论坛上有人说我不应该使用 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/