JavaFX pathTransition同时运行

时间:2017-09-23 08:49:17

标签: java javafx

我想用FX做一个像这样的小动画(见图像 - Bean Machine),共10个球。但是我发现在我的for循环中,一旦我创建了PathTransition,这些圆圈将同时运行然后以相同的速度停止。所以我想知道我的代码出了什么问题,为什么不一个一个地连续运行这个圆圈呢?

        Trace[] traces = new Trace[10];//this is every circle's trace, I wrote another class to deal with its trace
        PathTransition[] pathTransitions = new PathTransition[10];//this is animation for every circle

        for (int i = 0; i < 10; i++) {
            traces[i] = new Trace();
            pathTransitions[i] = new PathTransition();

            //draw Trace --circle
            Circle MovableCircle = new Circle(300, 40, 5);
            MovableCircle.setFill(Color.color(Math.random(), Math.random(), Math.random()));
            pane.getChildren().add(MovableCircle);
            pathTransitions[i].setDuration(Duration.millis(5000));

            //draw Trace -- trace, in order to observe clearly I draw them in the image. 
            traces[i].DrawTrace();
            pane.getChildren().add(traces[i]);
            pathTransitions[i].setPath(traces[i]);
            pathTransitions[i].setNode(MovableCircle);
            pathTransitions[i].setCycleCount(1);
            pathTransitions[i].play();
        }

enter image description here

0 个答案:

没有答案