我正在尝试让一个节点遵循以下路径:

但我真的很难让它正常工作。目前,我让它这样做:

有人知道如何让它正常工作吗?下面是我当前的代码:
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();
}
}发布于 2017-01-22 07:35:01
我一开始就应该使用它,但是我通过使用QuadCurveTo而不是ArcTo使它工作

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();
}
}https://stackoverflow.com/questions/41783595
复制相似问题