Javafx 简明教程

JavaFX - Animations

一般来说,为对象制作动画意味着通过快速显示创建其运动的错觉。动画在应用程序中用于对元素(如图像、文本、绘图等)添加某些特殊视觉效果。您可以在文本上指定进入和退出效果,淡入淡出图像,一个接一个地显示项目符号(如果有)等。引入动画的概念是为了在视觉上增强应用程序。

In general, animating an object implies creating illusion of its motion by rapid display. Animations are used in an application to add certain special visual effects on elements like images, text, drawings, etc. You can specify the entry and exit effects on a text, fading an image in and out, displaying bulleted points (if any) one after the other, etc. The concept of animation is introduced to visually enhance an application.

由于JavaFX也是用于创建此类UI应用程序的软件,因此它支持动画的概念。

As JavaFX is also a software that is used to create such UI applications, it supports the concept of Animations.

Animations in JavaFX

在JavaFX中,可以通过随着时间的推移更改节点的属性为其制作动画。JavaFX提供了一个名为 javafx.animation 的包。此包包含用于为节点制作动画的类。动画是所有这些类的基类。

In JavaFX, a node can be animated by changing its property over time. JavaFX provides a package named javafx.animation. This package contains classes that are used to animate the nodes. Animation is the base class of all these classes.

使用JavaFX,您可以应用以下动画(过渡):

Using JavaFX, you can apply animations (transitions) such as −

所有这些过渡都由包 javafx.animation 中的各个类表示。除此之外,JavaFX 还提供类以对节点应用更多过渡。

All these transitions are represented by individual classes in the package javafx.animation. In addition to these, JavaFX provides classes to apply more transitions on nodes.

JavaFX 所支持的其他过渡类型如下:

The following are the other kinds of transitions supported by JavaFX.

  1. Transitions that effects the attributes of the nodes: Fade, Fill, Stroke Transitions

  2. Transition that involve more than one basic transitions: Sequential, Parallel, Pause Transitions

  3. Transition that translate the object along the specified path: Path Transition

Applying Animation to JavaFX Node

如需对节点应用特定动画,您必须执行以下步骤:

To apply a particular animation to a node, you have to follow the steps given below −

  1. Create a require node using respective class; for example, we use Rotate class to apply Rotate Transition.

  2. Instantiate the respective transition (animation) class that is to be applied.

  3. Set the properties of the transition.

  4. Finally play the transition using the play() method of the Animation class.