JavaFx文本移动动画

标签 java animation javafx

嗨,我想做这样的事情:
我有文本,我希望文本始终从右向左移动。我想将移动文本的边界设置为 Pane 边界。现在我有了这个,但它没有按照我想要的方式工作

  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();

我想在我的应用程序中从右到左放置幻灯片文本

最佳答案

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

时间轴时间轴 = new Timeline(initFrame, endFrame); --> 时间轴时间轴 = new Timeline(initFrame);

希望我能帮助你。

编辑:

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

关于JavaFx文本移动动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39571550/

相关文章:

java - 在 Veracode 中使用 slf4j LOGGER 时出现 CRLF 注入(inject)漏洞 (CWE 117)

jQuery,单击时连续调用多个动画

android - 将动画 View 保持在最终动画位置

鼠标/拖动事件上的 JavaFX 飞盘运动

JavaFX - GridPane 背景图像

JavaFX 通过 CSS 为按钮的图形节点设置样式

java - 检查数组是否为空,但不为空

java.lang.VerifyError : Expecting a stackmap frame at branch target 错误

java - 在java中更新现有文件

iOS - 动画不重复