JavaFX PathTransition set cycle count

Description

JavaFX PathTransition set cycle count

import javafx.animation.PathTransition;
import javafx.animation.PathTransition.OrientationType;
import javafx.animation.Timeline;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.layout.Pane;
import javafx.scene.paint.Color;
import javafx.scene.shape.Arc;
import javafx.scene.shape.Circle;
import javafx.stage.Stage;
import javafx.util.Duration;

public class Main extends Application {

    private static double WIDTH = 400;
    private static double HEIGHT = 400;


    @Override//from ww w. jav a 2s .  c  om
    public void start(Stage primaryStage) throws Exception {
        Pane pane = new Pane();
        Arc arc = new Arc(WIDTH / 2, HEIGHT * 0.8, WIDTH * 0.25, HEIGHT * 0.1, 180, 180);
        arc.setFill(Color.TRANSPARENT);
        arc.setStroke(Color.BLACK);
        Circle c = new Circle(arc.getCenterX() - arc.getRadiusX(), arc.getCenterY(), 10);

        pane.getChildren().addAll(c, arc);

        PathTransition path = new PathTransition();
        path.setDuration(Duration.millis(4000));
        path.setPath(arc);
        path.setNode(c);
        path.setOrientation(OrientationType.NONE);
        path.setCycleCount(Timeline.INDEFINITE);
        path.setAutoReverse(true);
        path.play();
        c.setOnMouseClicked(e -> {
            path.play();
        });

        Scene scene = new Scene(pane, WIDTH, HEIGHT);
        primaryStage.setScene(scene);
        primaryStage.setTitle("Swing");
        primaryStage.show();
    }


    public static void main(String[] args) {
        Application.launch(args);
    }
}



PreviousNext

Related