【问题标题】:Multiple timeline animation in javafx-8javafx-8 中的多个时间轴动画
【发布时间】:2017-03-10 11:43:47
【问题描述】:

Region 表面上有很多 ImagePanel。我将它们保存在组中。它们应该水平滚动。enter image description here

我为此编写了一些方法。 例如。左侧切换位置。 (rects - 矩形。之前是矩形)。

//---------     OO<->OO   OOOOOO   OOOO        -----------------------
  private void shiftAnimatedInLeft(ObservableList rects)
  {
    ParallelTransition pt = new ParallelTransition();
    for (int i = 0; i < rects.size(); i++)
    {
      double startPosition = ((ImagePanel) rects.get(i)).getTranslateX();
      double finishPosition = -(rects
              .size() - i) * getSideImageOffset() - getCenterOffset() - (IMAGE_WIDTH * (1 - SCALE_SMALL) / 2);
      Timeline timeline = new Timeline();
  timeline.getKeyFrames().addAll(
          new KeyFrame(new Duration(0),
                       new KeyValue(((ImagePanel) rects.get(i)).translateXProperty(),
                                    startPosition,
                                    INTERPOLATOR)),
          new KeyFrame(new Duration(500),
                       new KeyValue(((ImagePanel) rects.get(i)).translateXProperty(),
                                    finishPosition,
                                    INTERPOLATOR))
  );
  pt.getChildren().add(timeline);
//      timeline.play();
    }
    pt.play();
  }

例如将元素从中心向左移动。

//---------     OOOO   <-OOOOOO   OOOO        -----------------------


private void shiftAnimatedCenterToLeft(ImagePanel rect)
  {
    double startPosition = rect.getTranslateX();
    double finishPosition = - getSideImageOffset() - getCenterOffset() - (IMAGE_WIDTH*(1-SCALE_SMALL)/2);

Timeline timeline = new Timeline();
timeline.getKeyFrames().addAll(
        new KeyFrame(new Duration(0),
                     new KeyValue(rect.translateXProperty(), startPosition, INTERPOLATOR),
                     new KeyValue(rect.scaleXProperty(), rect.getScaleX(), INTERPOLATOR),
                     new KeyValue(rect.scaleYProperty(), rect.getScaleY(), INTERPOLATOR),
                     new KeyValue(rect.angle, -270.0, INTERPOLATOR),
                     new KeyValue(rect.opacity, 1.0, INTERPOLATOR),
                     new KeyValue(rect.vboxStyle, "imagePanelBlackVBox", INTERPOLATOR)),
        new KeyFrame(new Duration(500),
                     new KeyValue(rect.translateXProperty(), finishPosition, INTERPOLATOR),
                     new KeyValue(rect.scaleXProperty(), SCALE_SMALL, INTERPOLATOR),
                     new KeyValue(rect.scaleYProperty(), SCALE_SMALL, INTERPOLATOR),
                     new KeyValue(rect.angle, ANGLE, INTERPOLATOR),
                     new KeyValue(rect.opacity, 0.0, INTERPOLATOR),
                     new KeyValue(rect.vboxStyle, "imagePanelWhiteVBox", INTERPOLATOR))
);
timeline.play();
  }

等等。

这些方法使用 onKeyPressed (left\right) 或鼠标滚轮滚动事件。

最后,问题:如果我尝试在一个独立的应用程序中使用它,它可以正常工作(但不是很好)。但是,如果我尝试将其集成到另一个应用程序中,这一切都会变得非常滞后并减慢整体动画速度。

【问题讨论】:

    标签: animation javafx-8 timeline


    【解决方案1】:

    您可以使用 Platform.runLater() 在另一个线程中运行动画-也许它会有所帮助-或使用 JProfiler(或任何其他免费的等效工具)之类的分析器测试应用程序的性能,并优化代码中最苛刻的部分。

    【讨论】:

    • 没有。非常糟糕的主意!不要将其他线程用于动画! Timeline 非常适合。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-08-13
    • 1970-01-01
    • 1970-01-01
    • 2017-04-04
    • 1970-01-01
    • 2012-05-30
    相关资源
    最近更新 更多