3 Replies Latest reply: Feb 11, 2013 12:17 PM by jsmith RSS

    JavaFX 2.2 How to define a pivot point for a RotateTransition object.

    915866
      Hi,

      My problem is that I'm not able to find a way to define a pivot point for a rotation transition element. In other words, I need an animated equivalent, if available, for the following code snippet:

      Rotate rotate = new Rotate(0,*XPivot*,*YPivot*);
      Object.getTransforms().clear();
      Object.getTransforms().add(rotate);


      Any tip or solution is much appreciated

      Thanks

      Edited by: user10280119 on Feb 10, 2013 11:56 AM
        • 1. Re: JavaFX 2.2 How to define a pivot point for a RotateTransition object.
          James_D
          You can apply a Timeline to the angleProperty of the rotation you just defined.
          KeyValue start = new KeyValue(rotate.angleProperty(), 0);
          KeyValue end = new KeyValue(rotate.angleProperty(), 360);
          Animation rotateAnimation = new Timeline(new KeyFrame(Duration.ZERO, start), new KeyFrame(Duration.seconds(1), end));
          • 2. Re: JavaFX 2.2 How to define a pivot point for a RotateTransition object.
            shakir.gusaroff
            Hi. You can also use a path transition :
            Here is an example:
            import javafx.animation.PathTransition;
            import javafx.animation.PathTransition.OrientationType;
            import javafx.application.Application;
            import javafx.event.ActionEvent;
            import javafx.event.EventHandler;
            import javafx.scene.Scene;
            import javafx.scene.control.Button;
            import javafx.scene.layout.StackPane;
            import javafx.scene.paint.Color;
            import javafx.scene.shape.Circle;
            import javafx.scene.shape.CubicCurveTo;
            import javafx.scene.shape.MoveTo;
            import javafx.scene.shape.Path;
            import javafx.scene.shape.Rectangle;
            import javafx.stage.Stage;
            import javafx.util.Duration;
            
            public class PathTransitionSample2 extends Application {
            
                @Override
                public void start(Stage primaryStage) {
            
            
                    Rectangle rect = new Rectangle(100, 40, 20, 20);
                    rect.setFill(Color.VIOLET);
                    Circle circle = new Circle(150, 50, 30);
                    PathTransition pathTransition = new PathTransition();
            
                    pathTransition.setDuration(Duration.millis(5000));
                    pathTransition.setNode(rect);
                    pathTransition.setPath(circle);
                    pathTransition.setOrientation(OrientationType.ORTHOGONAL_TO_TANGENT);
                    pathTransition.setCycleCount(1);
                    pathTransition.setAutoReverse(true);
            
                    StackPane root = new StackPane();
                    root.getChildren().add(rect);
            
                    Scene scene = new Scene(root, 300, 250);
                    primaryStage.setTitle("Path transition");
                    primaryStage.setScene(scene);
                    primaryStage.show();
                                    
                    pathTransition.play();
                            
                }
            
                public static void main(String[] args) {
                    launch(args);
                }
            }
            • 3. Re: JavaFX 2.2 How to define a pivot point for a RotateTransition object.
              jsmith
              JavaFX 2.2 How to define a pivot point for a RotateTransition object.
              There is an existing (not implemented in JavaFX 2.2) feature request for this:
              http://javafx-jira.kenai.com/browse/RT-18540 "Define rotation center in RotateTransition"