1
我的目的是創建一個遊戲,在該遊戲中向目標發射球。不過,我更喜歡這個問題的一般答案。使用路徑轉換時對衝突沒有反應
Circle ball = new Circle(x1,y1,r);
Rectangle rect = new Rectangle(x2,y2,w,h);
Line path = new Line(x1,y1,x3,y3);
PathTransition pathTrans = new PathTransition(Duration.millis(t), path, ball);
pathTrans.play();
if (ball.getBoundsInParent().intersects(rect.getBoundsInParent()))
{
//foo
}
爲什麼程序不能捕捉到碰撞?
如果需要澄清,我很樂意提供更多信息。
順便提一句,這些形狀的邊界將是完全包含形狀的最小矩形。因此,如果圓形點擊角落上的矩形,您仍然會看到兩個形狀的可見部分之間的小間隙。您可能需要做大量的幾何才能獲得非常好的碰撞檢測功能。 – 2014-12-05 02:30:14