【问题标题】:JavaFx text movement animationJavaFx 文本移动动画
【发布时间】:2016-09-19 11:00:29
【问题描述】:

您好,我想做这样的事情:
我有文字,我希望文字一直从右向左移动。我想为移动文本设置边界是窗格边界。现在我有了这个,但它并没有按照我想要的方式工作

  public static void start(Text msg) {
    msg.setTextOrigin(VPos.TOP);
    double sceneWidth = Config.xSize;
    double msgWidth = msg.getLayoutBounds().getWidth();
    KeyValue initKeyValue = new KeyValue(msg.translateXProperty(), sceneWidth);
    KeyFrame initFrame = new KeyFrame(Duration.ZERO, initKeyValue);
    KeyValue endKeyValue = new KeyValue(msg.translateXProperty(), -1.0
        * msgWidth);
    KeyFrame endFrame = new KeyFrame(Duration.seconds(50), endKeyValue);
    Timeline timeline = new Timeline(initFrame, endFrame);
    timeline.setCycleCount(Timeline.INDEFINITE);
    timeline.play();

我想在我的应用程序中有一个从右到左的幻灯片文本

【问题讨论】:

  • 你的意思是它没有按照你想要的方式工作?是不是只有一次动画?还是什么都没发生?或者它正在颠倒?怎么了?我们提供帮助的能力仅限于您帮助我们了解问题的程度。
  • @iMan 我编辑我的帖子

标签: java animation javafx


【解决方案1】:

您不需要KeyValue endKeyValueKeyFrame endFrame --> 删除它们。在timeline.play();之前添加timeline.setAutoReverse(true);

Timeline timeline = new Timeline(initFrame, endFrame); --> Timeline timeline = new Timeline(initFrame);

希望我能帮助你。

编辑:

initFrame 的持续时间更改为Duration.seconds(50) 或其他内容。

【讨论】:

    猜你喜欢
    • 2022-01-05
    • 1970-01-01
    • 2021-08-17
    • 2018-01-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-02-19
    • 1970-01-01
    相关资源
    最近更新 更多