0
我正在使用JavaFx 8庫。javafx碰撞問題的路徑(行)與粗筆畫和圓圈
我的任務很簡單:我想檢查一下圓周是否與周圍有粗的筆畫碰撞。問題是Path.intersect()和Shape.intersect()函數都會忽略路徑/線條周圍的筆劃。
Path tempPath = new Path(player.getPath().getElements());
//player.getDot() is Circle
if(tempPath.intersects(player.getDot().getBoundsInParent())){
Shape intersect = Shape.intersect(tempPath, player.getDot());
if(intersect.getBoundsInLocal().getWidth() != -1){
System.out.println("Path Collision occurred");
}
}
我的路徑是由許多LineTo對象組成的。 格式是這樣的:
/** Creates path and player dot */
private void createPath() {
this.path = new Path();
this.path.setStrokeWidth(20);
this.path.setStroke(Color.RED);
this.path.setStrokeLineCap(StrokeLineCap.ROUND);
this.path.setStrokeLineJoin(StrokeLineJoin.ROUND);
this.dot = new Circle(10, Color.BLUE);
this.dot.setOpacity(1);
}
我該如何實現成功的碰撞檢測?
你是對的,碰撞工作正常。我發現我的錯誤在Path對象的重複中。 Path tempPath = new Path(player.getPath()。getElements());) 舊路徑的屬性(如Stroke和Color)沒有轉移到新路徑。因此需要重新分配屬性。 –