2017-04-20 265 views
0

如果可能的話,可以使用SceneBuilder旋轉一條不在中心但與另一個關鍵點不同的線,如果可能的話?感謝幫助。圍繞樞軸旋轉線? SceneBuilder JavaFx

即時通訊使用此代碼,但現在的支點是在中心:

@FXML 
private Line lancettaQuadroCentrale; 

@FXML 

private void handleButtonAction(ActionEvent event) { 
     System.out.println("You clicked me!");   
     RotateTransition rt = new RotateTransition(Duration.seconds(4),lancettaQuadroCentrale); 
     rt.setByAngle(0); 
     rt.setToAngle(220); 
     rt.setCycleCount(Timeline.INDEFINITE); 
      rt.setAutoReverse(true); 
     rt.play(); 
    } 
+0

看到這個[旋轉變換演示應用程序](https://gist.github.com/jewelsea/1475424),也許那裏說明的概念將幫助你。 – jewelsea

回答

0

你可以使用一個Timeline動畫的angle財產a Rotate transform適用於Line

@FXML 
private void handleButtonAction() { 
    System.out.println("You clicked me!"); 

    Rotate rotate = new Rotate(0, pivotX, pivotY); 

    lancettaQuadroCentrale.getTransforms().add(rotate); 

    Timeline timeline = new Timeline(new KeyFrame(Duration.ZERO, new KeyValue(rotate.angleProperty(), 0d)), 
            new KeyFrame(Duration.seconds(4), new KeyValue(rotate.angleProperty(), 220d)));  

    timeline.setCycleCount(Animation.INDEFINITE); 
    timeline.setAutoReverse(true); 

    timeline.play(); 
} 
+0

嗨,netbeans報告此錯誤「KeyValue是抽象的,不能被實例化」在時間線上的行 –

+0

解決了導入javafx.animation.KeyValue;但給我一個奇怪的旋轉不是一個正常的翻譯:P –

+0

@FrancescoValla你能描述一下預期的結果嗎?層次結構如何顯示(例如,您是否使用'Group'作爲父項)? – fabian

0

RotateTransition設置軸:

rt.setAxis(new Point3D(10, 0, 0));