【发布时间】:2013-07-28 11:29:43
【问题描述】:
我有一个带有子弹和怪物的游戏,其中我需要在使用矩形碰撞时释放子弹和怪物,但是当发生碰撞时,该方法不会返回 true
这是我所做的: 我为每个子弹/怪物设置界限
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++;
}
我在每个边界上都有日志,它们都是正确的 left
【问题讨论】:
-
它应该是轴对齐(不旋转)矩形到矩形碰撞检查吗?
-
是的,它是轴对齐的,相交仅用于旋转矩形?
-
我不确定,因为我从来没有使用过它,我只是做了我自己的相交检查方法,我在下面向你展示了。看看吧
-
我将 if 语句更改为你所说的,但我仍然没有得到日志...
-
好吧,问题都是关于碰撞检测不起作用,而我向您展示的检测方法正在正常工作。除非您没有将其正确应用于您的代码,否则这意味着问题出在其他地方。确保您传递给碰撞检测方法的坐标是正确的,并代表您在屏幕上实际获得的坐标。如果这又不是问题,那么您应该仔细检查您的游戏逻辑。
标签: android collision rectangles