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