Android 矩形碰撞检测不工作
我有一个关于子弹和怪物的游戏,其中我需要在子弹和怪物使用矩形碰撞时释放它们,但是当碰撞发生时,该方法不会返回true 以下是我所做的: 我为每一颗子弹/怪物设定了边界Android 矩形碰撞检测不工作,android,collision,rectangles,Android,Collision,Rectangles,我有一个关于子弹和怪物的游戏,其中我需要在子弹和怪物使用矩形碰撞时释放它们,但是当碰撞发生时,该方法不会返回true 以下是我所做的: 我为每一颗子弹/怪物设定了边界 bounds.left = (int)X; bounds.top = (int)Y ; bounds.right = (int)X + monsterWidth; bounds.bottom = (int)Y + monsterHeight; 然后提出了一种布尔方法 return bounds.intersect((int)X,
bounds.left = (int)X;
bounds.top = (int)Y ;
bounds.right = (int)X + monsterWidth;
bounds.bottom = (int)Y + monsterHeight;
然后提出了一种布尔方法
return bounds.intersect((int)X,(int) Y ,(int) X + monsterWidth, (int) Y + monsterHeight);
我有这两个界限,然后我在游戏线程中调用它们
int i=0, j=0;
while (!monster.isEmpty() && monster.size()>i){
j=0;
while (!bullets.isEmpty() && bullets.size()>j){
if(monster.get(i).isColliding(bullets.get(j).getBounds())){
Log.v("collided", "Collided!");
monster.get(i).setRelease(true);
bullets.get(j).setRelease(true);
}
j++;
}
i++;
}
我在每个边界上都有日志,它们都是正确的左这是我的矩形到矩形碰撞检查方法(假设两个矩形都是轴对齐的) _x1,x2,y1,y2使用相同的公式,但表示第二个矩形
bool boolResult = false;
if (x2 >= _x1 && x1 <= _x2 && y2 >= _y1 && y1 <= _y2)
{
boolResult = true;
}
return boolResult;
bool boolResult=false;
如果(x2>=\ux1&&x1=\uy1&&y1我已通过更改解决了此问题:
return bounds.intersect
到
就是这样。~它应该是轴对齐的(不旋转)矩形到矩形碰撞检查?是的,它是轴对齐的,相交仅用于旋转矩形吗?我不确定,因为我从未使用过它,我只是制定了我自己的相交检查方法,我在下面向您展示。检查它。我将if语句更改为您所说的语句,但仍然没有得到日志…问题是关于colli的sion检测不工作,我向您展示的检测方法正常工作。除非您没有将其正确应用于代码,否则这意味着问题出在其他地方。请确保传递给碰撞检测方法的坐标正确,并代表您在屏幕上实际得到的坐标。如果是,请再次说明问题是,你应该仔细检查你的游戏逻辑。
return bounds.intersect
bounds.contains(r)