【问题标题】:Why is my JavaFX PathTransition invisible?为什么我的 JavaFX PathTransition 不可见?
【发布时间】:2014-06-06 08:05:24
【问题描述】:

我从网上复制了一些代码,与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);

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

我必须做些什么才能使可视化真正发挥作用?

【问题讨论】:

    标签: animation javafx transition invisible


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 2015-10-02
      • 1970-01-01
      • 2015-10-05
      • 2015-07-11
      • 2018-06-02
      • 2023-03-19
      • 2011-07-08
      • 2016-08-13
      • 2012-12-30
      相关资源
      最近更新 更多