I made a few edits to your code and it seems to work for me
scene.addEventHandler(MouseEvent.MOUSE_CLICKED, new EventHandler<MouseEvent>() {
@Override
public void handle(MouseEvent me){
Circle circle = new Circle(10, 20,50);
circle.setFill(Color.GREEN);
root.getChildren().add(circle);
Animation animation = ParallelTransitionBuilder.create()
.node(circle)
.children(
TranslateTransitionBuilder.create()
.duration(Duration.seconds(2))
.fromX(me.getSceneX())
.toX(me.getSceneX()+10)
.build()
)
.cycleCount(Timeline.INDEFINITE)
.autoReverse(true)
.build();
animation.play();
}
});
Though, what I still don't get is the purpose of your
public void play() {
animation.play();
}
and where are you calling it !