JavaFX PathTransition 动画未播放

标签 java animation javafx

我有一些代码应该沿着圆弧的路径制作圆的动画:

package event_handling;

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.ArcType;
import javafx.scene.shape.Circle;
import javafx.stage.Stage;
import javafx.util.Duration;

public class PalindromeSwing extends Application {

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

@Override
public void start(Stage primaryStage) throws Exception {

    Pane pane = new Pane();

    System.out.println(pane.getWidth());

    Arc a = new Arc(100, 100, 100, 100, -135, 90);
    a.setType(ArcType.OPEN);
    a.setStroke(Color.BLACK);
    a.setFill(Color.TRANSPARENT);

    Circle c = new Circle(5);

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

    PathTransition pt = new PathTransition();

    pt.setDuration(Duration.INDEFINITE);
    pt.setNode(c);
    pt.setPath(a);
    pt.setOrientation(OrientationType.ORTHOGONAL_TO_TANGENT);
    pt.setCycleCount(Timeline.INDEFINITE);
    pt.setAutoReverse(true);
    pt.play();

    Scene scene = new Scene(pane, 400, 400);

    primaryStage.setTitle("Animated circle");
    primaryStage.setScene(scene);
    primaryStage.show();

 }

}

但是,当我运行该程序时,没有动画发生。圆出现在圆弧的开头,但没有任何反应:

enter image description here

请帮我理解原因。

最佳答案

您必须为动画设置明确的持续时间,例如

pt.setDuration(Duration.seconds(4));

该值决定一个动画周期的持续时间。

Duration.INDEFINITE 定义为 Duration(Double.POSITIVE_INFINITY)。使用它将使动画播放无限持续时间,导致插值步长变得太小而无法对动画节点产生影响。

关于JavaFX PathTransition 动画未播放,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29993025/

相关文章:

java - OrmLite 与 BigData - java.lang.OutOfMemoryError

android - 在android中循环图像帧

javascript - jQuery:同时设置元素位置和不透明度的动画

JavaFx:标签文本宽度

Javafx 可编辑表格单元格

java - 空指针异常 - 从 fragment 加载新 Activity

Java 一行如果不适用于打印

Java 使用的内存远多于使用 -Xmx 分配的内存

javascript - CSS/JS 图片滑出动画

JavaFX 8.0 : How to change the focus traversal key?