📅  最后修改于: 2020-10-14 03:28:02             🧑  作者: Mango
此过渡通过X,Y和Z三个方向中的任意一个或全部,通过指定因子对指定持续时间内节点的缩放进行动画处理。
在JavaFX中,ScaleTransition由类javafx.animation.ScaleTransition表示。我们需要实例化此类,以生成适当的比例转换。
物产
下表描述了类的属性及其设置方法。
Property | Description | Setter Methods |
---|---|---|
byX | This is a double type property. It represents the incremented stop X factor value. | setByX(double value) |
byY | This is a double type property. It represents the incremented stop Y factor value. | setByY(double value) |
byZ | This is a double type property. It represents the incremented stop Z factor value. | setByZ(double value) |
duration | This is an object type property of the class Duration . It represents the duration of scale transition. | setDuration(Duration value) |
fromX | This is a double type property. It represents the start X value of ScaleTransition. | setFromX(double value) |
fromY | This is a double type property. It represents the start Y value of ScaleTransition. | setFromY(double value) |
fromZ | This is a double type property. It represents the start Z value of ScaleTransition. | setFromZ(double value) |
node | This is an object type property of the class Node. It represents onto which, the scale transition is applied. | setNode(Node node) |
toX | This is a double type property. It represents the stop X scale value of the scale transition. | setToX(double value) |
toY | This is a double type property. It represents the stop Y scale value of the scale transition. | setToY(double value) |
toZ | This is a double type property. It represents the stop Z scale value of the scale transition. | setToZ(double value) |
该类中有三个构造函数。
在下面的示例中,我们制作了一个圆,将自己在X方向平移400。
package application;
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.Circle;
import javafx.stage.Stage;
import javafx.util.Duration;
public class Translate_Transition extends Application{
@Override
public void start(Stage primaryStage) throws Exception {
// TODO Auto-generated method stub
//Creating the circle
Circle cir = new Circle(50,100,50);
//setting color and stroke of the cirlce
cir.setFill(Color.RED);
cir.setStroke(Color.BLACK);
//Instantiating TranslateTransition class
TranslateTransition translate = new TranslateTransition();
//shifting the X coordinate of the centre of the circle by 400
translate.setByX(400);
//setting the duration for the Translate transition
translate.setDuration(Duration.millis(1000));
//setting cycle count for the Translate transition
translate.setCycleCount(500);
//the transition will set to be auto reversed by setting this to true
translate.setAutoReverse(true);
//setting Circle as the node onto which the transition will be applied
translate.setNode(cir);
//playing the transition
translate.play();
//Configuring Group and Scene
Group root = new Group();
root.getChildren().addAll(cir);
Scene scene = new Scene(root,500,200,Color.WHEAT);
primaryStage.setScene(scene);
primaryStage.setTitle("Translate Transition example");
primaryStage.show();
}
public static void main(String[] args) {
launch(args);
}
}
输出: