2017-01-21 45 views
0

我试图做一个节点按照这个路径:包含arcTo使圆角风格的路径

enter image description here

但我有一个很难真正得到它的工作。目前,我有它这样做:

enter image description here

有人知道如何使这项工作正常?这里是我当前的代码:

import javafx.animation.PathTransition; 
import javafx.animation.Transition; 
import javafx.application.Application; 
import javafx.scene.Scene; 
import javafx.scene.layout.Pane; 
import javafx.scene.paint.Color; 
import javafx.scene.shape.ArcTo; 
import javafx.scene.shape.Circle; 
import javafx.scene.shape.MoveTo; 
import javafx.scene.shape.Path; 
import javafx.stage.Stage; 
import javafx.util.Duration; 

public class Test extends Application { 
    public void start(Stage primaryStage) throws Exception { 
     double fromX = 50; 
     double fromY = 400; 
     double toX = 300; 
     double toY = 300; 

     Circle node = new Circle(10); 

     MoveTo path1 = new MoveTo(); 
     path1.setX(fromX); 
     path1.setY(fromY); 
     ArcTo path2 = new ArcTo(); 
     path2.setX(toX); 
     path2.setY(toY); 
     path2.setRadiusX(.5); 
     path2.setRadiusY(1.0); 
     path2.setXAxisRotation(45.0); 
     path2.setSweepFlag(true); 
     //path2.setLargeArcFlag(true); 
     Path path = new Path(path1, path2); 
     path.setStroke(Color.DODGERBLUE); 
     path.getStrokeDashArray().setAll(5d, 5d); 
     PathTransition secondMove = new PathTransition(Duration.seconds(2), path, node); 
     secondMove.setCycleCount(Transition.INDEFINITE); 

     Pane content = new Pane(node, path); 
     primaryStage.setScene(new Scene(content, 600, 600)); 
     primaryStage.show(); 

     secondMove.play(); 
    } 
} 

回答

0

我已经用它摆在首位,但我得到它通过使用QuadCurveTo而不是ArcTo工作:

enter image description here

import javafx.animation.PathTransition; 
import javafx.animation.Transition; 
import javafx.application.Application; 
import javafx.scene.Scene; 
import javafx.scene.layout.Pane; 
import javafx.scene.paint.Color; 
import javafx.scene.shape.*; 
import javafx.stage.Stage; 
import javafx.util.Duration; 

public class Test extends Application { 
    public void start(Stage primaryStage) throws Exception { 
     double fromX = 50; 
     double fromY = 400; 
     double toX = 300; 
     double toY = 300; 

     Circle node = new Circle(10); 

     MoveTo path1 = new MoveTo(); 
     path1.setX(fromX); 
     path1.setY(fromY); 
     QuadCurveTo path2 = new QuadCurveTo(); 
     path2.setX(toX); 
     path2.setY(toY); 
     path2.setControlX(fromX); 
     path2.setControlY(toY); 
     Path path = new Path(path1, path2); 
     path.setStroke(Color.DODGERBLUE); 
     path.getStrokeDashArray().setAll(5d, 5d); 
     PathTransition secondMove = new PathTransition(Duration.seconds(2), path, node); 
     secondMove.setCycleCount(Transition.INDEFINITE); 

     Pane content = new Pane(node, path); 
     primaryStage.setScene(new Scene(content, 600, 600)); 
     primaryStage.show(); 

     secondMove.play(); 
    } 
}