0
我必须提交一个Breakout克隆,并且我正在为球和砖的碰撞检测而努力。基本上,碰撞检测是有效的,但是球破坏了距视觉对象约10个像素的砖。我正在检查两个物体的边界,但我想问题是球是移动物体,而砖是静态物体。碰撞检测无法正常工作
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
brick = brickArray[i][j];
if (brick == null)
continue;
areBricksLeft = true;
Bounds brickBounds = brick.getBoundsInParent();
Bounds ballBounds = ball.getBoundsInParent();
if (brickBounds.intersects(ballBounds)) {
brick.removeBrickAt(i, j, brick, brickArray, brickPane);
didHitBrick = true;
}
}
}
我认为这是因为球的圆形,圆的x位置从中心开始,而矩形或方形的x位置开始。 –