ArcTo制作圆角样式的路径

时间:2017-01-21 19:32:07

标签: java javafx

我试图让节点遵循这条路径:

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();
    }
}

1 个答案:

答案 0 :(得分: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();
    }
}