我正在尝试使用 android rect 类实现 rect 碰撞 if 语句,但我似乎无法让它工作,它确实工作但返回语句永远不会正确,这是我的 if 语句
if(Rect.intersects(balls.get(j).topSide, levelBlocks.blocks.get(i).rect))
{
Log.d("Check", "Hit");
}
这是我打印的信息,确实表明应该发生碰撞
06-09 18:17:50.842: D/Check(6016): Bloc1X:192, Y:64, W:32, H:32
06-09 18:17:50.862: D/Check(6016): Ball X:199, Y:92, W:18, H:6
这是一张带有指向位置的图片,图像分辨率与应用程序画布相同
如果有人可以帮助我,那就太好了:)。
这是更多代码
if(i == 2)
{
Log.d("Check", "Ball X:"+ balls.get(j).topSide.left+",Y:"+ balls.get(j).topSide.top+", W:"+ balls.get(j).topSide.right+", H:"+balls.get(j).topSide.bottom);
Log.d("Check", "Bloc1X:"+ levelBlocks.blocks.get(i).rect.left+", Y:"+ levelBlocks.blocks.get(i).rect.top+", W:"+ levelBlocks.blocks.get(i).rect.right+", H:"+levelBlocks.blocks.get(i).rect.bottom);
}
if(Rect.intersects(balls.get(j).topSide, levelBlocks.blocks.get(i).rect))
{
Log.d("Check", "hit");
}