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 = 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();
}
public void play() {
animation.play();
}
//public void stop() {
//animation.stop()
我想在场景中circle move
时mouse click
。它没有发生!
我不确定序列是否错误,即在动画开始之前将对象添加到根?
答案 0 :(得分:1)
我对您的代码进行了一些编辑,它似乎对我有用
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();
}
});
尽管如此,我仍然没有得到的是
的目的public void play() {
animation.play();
}
你在哪里叫它!