0
我有幾個Shape對象 - Circle
,Rectangle
和Polygon
。與JavaFX中的.intersects()的2D碰撞 - 錯誤的準確性
我使用內置的.intersects(Bounds1, Bounds2)
方法來檢測碰撞,但它是相當不準確的。
爲什麼碰撞準確性如此糟糕,我該如何改進?碰撞檢測對於多邊形對象是非常不好的。從字面上看,至少有50個像素關閉。
編輯:這裏是我的代碼:
for (int i = 0; i < shapes.size(); i++) {
Bounds b1 = shapes.get(i).getBoundsInParent();
Bounds b2 = shapes.get(i).getBoundsInParent();
if (b1.intersects(b2)) {
//intersection happened and I remove the shapes from the scene
}
}
,這是我Polygon
s表示代表的ArrayList Shapes
的代碼。
class Monster {
Polygon poly;
Monster() {
poly = new Polygon(new double[] { 125.0,15.0, 150.0,30.0, 150.0,60.0, 125.0,75.0, 100.0,60.0, 100.0,30.0 });
}
}
我從來沒有經歷過的JavaFX邊界相交的任何誤差。請編輯您的問題,以包含[最低限度,完整,可驗證的示例](http://stackoverflow.com/help/mcve)來演示此問題。 – jewelsea
@jewelsea完成!添加了代表我的Monster class +碰撞檢測的代碼。 – Gregg1989
感謝Gregg,你能否讓我可以複製粘貼來編譯和運行。 – jewelsea