Combining transitions

There are only two options here: ParallelTransition, which runs several animations in parallel, and SequentialTransition, which runs them one by one.

Note that these transitions work with the Animation class, which means you can combine both Transition and Timeline.

Both transitions take a node and a set of animations and apply these animations to that node unless some animation has a specific node already set for them.

There is a special transition which does nothing for a period of time: PauseTransition. Its only use is to conveniently add pauses to SequentialTransition.

Let's see it in a small example:

// chapter5/transitions/SequentialTransitionDemo
public void start(Stage primaryStage) {

RotateTransition rotate = new RotateTransition(Duration.seconds(2));
rotate.setByAngle(90);

TranslateTransition translate = new TranslateTransition(Duration.seconds(1));
translate.setByX(100);

ScaleTransition scale = new ScaleTransition(Duration.seconds(1));
scale.setToX(0);
scale.setToY(0);

Node node = new Rectangle(50, 50, 100, 30);
Scene scene = new Scene(new Pane(node), 300, 300);
primaryStage.setScene(scene);
primaryStage.show();

SequentialTransition sequential = new SequentialTransition(
translate, rotate, new PauseTransition(Duration.seconds(1)), scale);
sequential.setNode(node);
sequential.play();
}
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.12.108.175