个性化阅读
专注于IT技术分析

JavaFX旋转过渡

本文概述

JavaFX旋转过渡

此过渡用于将旋转过渡应用于节点。它将在指定的持续时间内沿三个轴中的任何一个旋转节点。

RotateTransition由类javafx.animation.RotateTransition表示。我们只需要实例化此类即可生成适当的RotateTransition。

物产

下表描述了类的属性及其设置方法。

属性 描述 设置方法
axis 这是Point3D类的对象类型属性。这代表旋转过渡轴。 setAxis(Point3D value)
byAngle 这是一个双精度类型的属性。这代表物体旋转的角度。 setByAngle(double value)
duration 这是Duration类的对象类型属性。这表示旋转过渡的持续时间。 setDuration(Duration value)
fromAngle 这是一个双精度类型的属性。它代表旋转过渡的起始角度。 setFromAngle(double value)
node 它是Node类的对象类型属性。它表示要在其上应用旋转过渡的节点。 setNode(Node value)
toAngle 这是一个双精度类型的属性。它表示旋转过渡的停止角值。 setToAngle(double value)

建设者

该类中有三个构造函数。

  1. public RotateTransition():使用默认参数创建RotateTransition的新实例。
  2. public RotateTransition(Duration duration):使用指定的持续时间值创建RotateTransition的新实例
  3. public RotateTransition(Duration duration, Node node):使用指定的持续时间值和应用了Node的节点创建RotateTransition的新实例。

在下面的示例中, 我们制作了一个沿Z轴旋转360度的矩形。

package application;
import javafx.animation.RotateTransition;
import javafx.application.Application;
import javafx.geometry.Point3D;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.paint.Color;
import javafx.scene.shape.Rectangle;
import javafx.scene.transform.Rotate;
import javafx.stage.Stage;
import javafx.util.Duration;
public class Rotate_Transition extends Application{

    @Override
    public void start(Stage primaryStage) throws Exception {
        // TODO Auto-generated method stub
    
        //Creating Rectangle 
        Rectangle rect = new Rectangle(200, 100, 200, 200);
        rect.setFill(Color.LIMEGREEN);
        rect.setStroke(Color.HOTPINK);
        rect.setStrokeWidth(5);
        
        //Instantiating RotateTransition class 
        RotateTransition rotate = new RotateTransition();
        
        //Setting Axis of rotation 
        rotate.setAxis(Rotate.Z_AXIS);
        
        // setting the angle of rotation 
        rotate.setByAngle(360);
        
        //setting cycle count of the rotation 
        rotate.setCycleCount(500);
        
        //Setting duration of the transition 
        rotate.setDuration(Duration.millis(1000));
        
        //the transition will be auto reversed by setting this to true 
        rotate.setAutoReverse(true);
            
        //setting Rectangle as the node onto which the 
// transition will be applied
        rotate.setNode(rect);
        
        //playing the transition 
        rotate.play();
        
        //Configuring Group and Scene 
        Group root = new Group();
        root.getChildren().add(rect);
        Scene scene = new Scene(root, 600, 400, Color.BLACK);
        primaryStage.setScene(scene);
        primaryStage.setTitle("Rotate Transition example");
        primaryStage.show();
        
    }
    public static void main(String[] args) {
        launch(args);
    }

}

输出:

JavaFX旋转过渡
赞(0)
未经允许不得转载:srcmini » JavaFX旋转过渡

相关推荐

评论 抢沙发

评论前必须登录!