📜  JavaFX 动画

📅  最后修改于: 2020-10-14 01:56:59             🧑  作者: Mango

JavaFX动画

通常,动画可以定义为创建对象运动神话的过渡。它是在指定持续时间内按顺序应用于对象的一组变换,以便可以在运动时显示该对象。

这可以通过快速显示帧来完成。在JavaFX中,包javafx.animation包含将动画应用到节点上的所有类。该程序包的所有类都扩展了javafx.animation.Animation类。

JavaFX为过渡提供了类,例如RotateTransition,ScaleTransition,TranslateTransition,FadeTransition,FillTransition,StrokeTransition等。

基本过渡

包javafx.animation提供了用于执行以下转换的类。

SN Transition Description
1 Rotate Transition Rotate the Node along one of the axes over the specified duration.
2 Scale Transition Animate the scaling of the node over the specified duration.
3 Translate Transition Translate the node from one position to another over the specified duration.
4 Fade Transition Animate the opacity of the node. It keeps updating the opacity of the node over a specified duration in order to reach a target opacity value
5 Fill Transition Animate the node’s fill color so that the fill color of the node fluctuates between the two color values over the specified duration.
6 Stroke Transition Animate the node’s stroke color so that the stroke color of the node fluctuates between the two color values over the specified duration.
7 Perform the list of transitions on a node in the sequential order.
8 Parallel Transition Perform the list of transitions on a node in parallel.
9 Path Transition Move the node along the specified path over the specified duration.

应用动画的步骤

    • 创建目标节点并配置其属性。
Rectangle rect =新Rectangle(120,100,100,100); rect.setFill(Color.RED);
  • 实例化相应的过渡类
RotateTransition rotation = new RotateTransition();
  • 为过渡设置所需的属性,例如持续时间,周期数等。
rotation.setDuration(Duration.millis(1000)); rotation.setAxis(Rotate.Y_Axis); rotation.setCycleCount(500);
  • 设置将在其上应用过渡的目标节点。为此,请使用以下方法。
rotation.setNode(rect);
  • 最后,使用play()方法播放过渡。
rotation.play();