我试图获得2个矩形来检查碰撞,但我不能成功,我甚至创造了彼此之上但没有运气。
int testrectX = 0 ;
public Rect testRect = new Rect(testrectX, 500, testrectX +1, 400);
public Rect testRect2 = new Rect(testrectX, 500, testrectX +1, 400);
if (Rect.intersects(testRect, testRect2)) {
System.out.println("testRect intersects with testRect1");
}
答案 0 :(得分:0)
以下是您使用的构造函数的一些文档。
public Rect (int left, int top, int right, int bottom)
使用指定的坐标创建一个新矩形。注意:不执行范围检查,因此调用者必须确保左< = right和top< = bottom。
正如eduyayo评论的那样,你创建了带顶部>的矩形。在底部,我相信Rect.intersects将它们标识为具有空交叉点的空矩形。尝试确保矩形构造为非空的。
答案 1 :(得分:0)
谢谢你们,我错过了这个
通过使顶部小于底部
来修复public Rect testRect = new Rect(testrectX, 300, testrectX +1, 400);
public Rect testRect2 = new Rect(testrectX, 300, testrectX +1, 400);