为什么我的JavaFX PathTransition不可见?

时间:2014-06-06 08:05:25

标签: animation javafx transition invisible

我从互联网上复制了一些代码,类似于official JavaFX sample page上的代码:

final Rectangle rectPath = new Rectangle (0, 0, 40, 40);
rectPath.setArcHeight(10);
rectPath.setArcWidth(10);
rectPath.setFill(Color.ORANGE);
Path path = new Path();
path.getElements().add(new MoveTo(20,20));
path.getElements().add(new CubicCurveTo(380, 0, 380, 120, 200, 120));
path.getElements().add(new CubicCurveTo(0, 120, 0, 240, 380, 240));
PathTransition pathTransition = new PathTransition();
pathTransition.setDuration(Duration.millis(4000));
pathTransition.setPath(path);
pathTransition.setNode(rectPath);
pathTransition.setOrientation(PathTransition.OrientationType.ORTHOGONAL_TO_TANGENT);
pathTransition.setCycleCount(Timeline.INDEFINITE);
pathTransition.setAutoReverse(true);
pathTransition.play();
// add the path to a pane:
myPane.getChildren().add(path);

现在我得到的只是路径但没有浮动矩形:

我需要做些什么才能实现可视化?

1 个答案:

答案 0 :(得分:0)

您需要将矩形(rectPath)添加到场景中,否则您将看不到它:

myPane.getChildren().add(path, rectPath);