我有一个PathTransition可以移动由2条路径组成的ImageView。
我想在动画持续时间达到一半时添加一个动作。
我看到通过getCuePoints方法,我们可以在某些时候添加标记,但是我不知道如何在动作中链接该标记:/
您有想法吗?
谢谢! :)
答案 0 :(得分:3)
使用ParallelTransition
运行PauseTransition
,持续时间为PathTransition
的一半。这使您可以使用onFinished
处理函数来触发事件:
public void start(Stage primaryStage) {
Path path = new Path(new MoveTo(), new CubicCurveTo(100, 100, 150, 50, 200, 100));
Rectangle rect = new Rectangle(10, 10);
Rectangle back = new Rectangle(100, 50, Color.RED);
back.setVisible(false);
// original transition
PathTransition transition = new PathTransition(Duration.seconds(5), path, rect);
// transition for triggering halftime event
PauseTransition pause = new PauseTransition(transition.getCycleDuration().multiply(0.5));
pause.setOnFinished(evt -> back.setVisible(true));
// combine & play transitions
ParallelTransition animation = new ParallelTransition(rect, transition, pause);
animation.play();
Scene scene = new Scene(new Pane(back, rect), 300, 300);
primaryStage.setScene(scene);
primaryStage.show();
}