Flip a card animation

前端 未结 2 562
情深已故
情深已故 2020-12-09 06:27

I\'m trying to flip a coloured rectangle. Is it possible to use the rotateTransition to do this?

I have tried the following code:

 public void rotate         


        
2条回答
  •  没有蜡笔的小新
    2020-12-09 07:17

    Not in 2D world. But you can imitate card flip using two ScaleTransitions:

    Rectangle front = new Rectangle(50, 50);
    
    ScaleTransition stHideFront = new ScaleTransition(Duration.millis(1500), front);
    stHideFront.setFromX(1);
    stHideFront.setToX(0);
    
    Rectangle back = new Rectangle(50, 50, Color.RED);
    back.setScaleX(0);
    
    ScaleTransition stShowBack = new ScaleTransition(Duration.millis(1500), back);
    stShowBack.setFromX(0);
    stShowBack.setToX(1);
    
    stHideFront.setOnFinished(new EventHandler() {
        @Override
        public void handle(ActionEvent t) {
            stShowBack.play();
        }
    });
    
    StackPane root = new StackPane();
    root.getChildren().addAll(front, back);
    Scene scene = new Scene(root, 300, 250);
    primaryStage.setScene(scene);
    
    primaryStage.show();
    stHideFront.play();
    

提交回复
热议问题