JavaFX暂停过渡

本文概述

  • 属性
  • 构造函数
顾名思义, 此过渡用于在按顺序应用到节点的多个动画之间暂停。在此过渡的生命周期内, 该节点在屏幕上保持不动。
在JavaFX中, 类javafx.animation.PauseTransition表示此转换。我们只需要实例化此类即可创建适当的暂停过渡。
属性
属性 描述 设置方法
duration 它是Duration类的一种对象。它代表了过渡的生命周期。 setDuration(Duration duration)
构造函数 该类中有两个构造函数。
  1. public PauseTransition():使用默认参数创建PauseTransition的新实例。
  2. public PauseTransition(Duration duration):使用指定的持续时间创建PauseTransition的新实例。

【JavaFX暂停过渡】在下面的示例中, 我们在多边形上应用了多个动画。每次转换后, 我们为节点提供了1秒的暂停。
package application; import javafx.animation.FadeTransition; import javafx.animation.PauseTransition; import javafx.animation.RotateTransition; import javafx.animation.SequentialTransition; import javafx.animation.TranslateTransition; import javafx.application.Application; import javafx.scene.Group; import javafx.scene.Scene; import javafx.scene.paint.Color; import javafx.scene.shape.Polygon; import javafx.stage.Stage; import javafx.util.Duration; public class Pause_Transition extends Application{ @Override public void start(Stage primaryStage) throws Exception { // TODO Auto-generated method stub //Creating polygon Polygon poly = new Polygon(); poly.getPoints().addAll(new Double[] {320.0, 270.0, 270.0, 220.0, 270.0, 270.0, 320.0, 120.0, 370.0, 270.0, 370.0, 220.0}); //Setting Color and Stroke properties for the polygon poly.setFill(Color.LIMEGREEN); poly.setStroke(Color.BLACK); //Setting Rotate Transition RotateTransition rt = new RotateTransition(Duration.millis(500), poly); rt.setByAngle(180); rt.setCycleCount(2); rt.setAutoReverse(true); //Setting Translate Transition TranslateTransition translate = new TranslateTransition(Duration.millis(500), poly); translate.setToX(-150f); translate.setCycleCount(2); translate.setAutoReverse(true); //Setting Fade Transition FadeTransition fade = new FadeTransition(Duration.millis(500), poly); fade.setFromValue(1.0f); fade.setToValue(0.5f); fade.setCycleCount(2); fade.setAutoReverse(true); //Setting Sequential Transition and pause after each transition passed in the list SequentialTransition seqTransition = new SequentialTransition (fade, new PauseTransition(Duration.millis(2000)), rt, new PauseTransition(Duration.millis(2000)), translate); //Playing Sequential Transition seqTransition.play(); //Setting Group and scene Group root = new Group(); root.getChildren().addAll(poly); Scene scene = new Scene(root, 490, 300, Color.WHEAT); primaryStage.setScene(scene); primaryStage.setTitle("Pause Transition Example"); primaryStage.show(); } public static void main(String[] args) { launch(args); } }

输出:
JavaFX暂停过渡

文章图片

    推荐阅读