JavaFx,Path Transition,直线

时间:2013-04-20 23:37:03

标签: java animation javafx

我正在研究javaFx应用程序。如何进行直线转换?我有两个矩形,我想要第一个矩形转到第二个矩形。 这是不起作用的代码:

 Rectangle r1 = rectangles.get(numbers[0]);
    Rectangle r2 = rectangles.get(numbers[1]);

    TranslateTransition translateTransition = new TranslateTransition();

    translateTransition.setNode(r1);
    translateTransition.setDuration(Duration.millis(1000));
    translateTransition.setFromX(r1.getX());
    translateTransition.setToX(r2.getX());

    TranslateTransition translateTransition2 = new TranslateTransition();

    translateTransition2.setNode(r2);
    translateTransition2.setDuration(Duration.millis(1000));
    translateTransition2.setFromX(0);
    translateTransition2.setToX(r1.getX() - r2.getX());
    translateTransition2.play();

    translateTransition.play();

0 个答案:

没有答案