Tino APCS

More Transitions

Use the ParallelTransition class to run simultaneous transitions on a Node.

// Create a Node. Could be any kind.
Rectangle rect = new Rectangle(50, 200, 100, 50);

// Create a Circle to use as our path Shape
Circle path = new Circle(300, 200, 100, Color.LIGHTBLUE);

// Create two Transitions
PathTransition pt = new PathTransition();
pt.setDuration(Duration.seconds(2));
pt.setPath(path);

RotateTransition rt = new RotateTransition();
rt.setDuration(Duration.seconds(2));
rt.setByAngle(-720);

// Add our transitions to a ParallelTransition
ParallelTransition groupTrans = new ParallelTransition();
groupTrans.getChildren().addAll(pt, rt);  // Add path and rotate
groupTrans.setNode(rect);  // Run on the rectangle
groupTrans.setCycleCount(2);  // Run twice
...
groupTrans.play();

Use the SequentialTransition class to run transitions as a playlist.

// Create a Node. Could be any kind.
Rectangle rect = new Rectangle(50, 200, 100, 50);

// Create a Circle to use as our path Shape
Circle path = new Circle(300, 200, 100, Color.LIGHTBLUE);

// Create two Transitions
PathTransition pt = new PathTransition();
pt.setDuration(Duration.seconds(2));
pt.setPath(path);

RotateTransition rt = new RotateTransition();
rt.setDuration(Duration.seconds(2));
rt.setByAngle(-720);

// Add our translations to a SequentialTransition
SequentialTransition groupTrans = new SequentialTransition();
groupTrans.getChildren().addAll(pt, rt);  // Add path and rotate
groupTrans.setNode(rect);  // Run on the rectangle
groupTrans.setCycleCount(2);  // Run twice
...
groupTrans.play();

PauseTransitions are useful when added to a SequentialTransition because they can insert a pause in a playlist of transitions.

// Transition 1
PathTransition pt = new PathTransition();
pt.setDuration(Duration.seconds(2));
pt.setPath(path);

// Pause Transition
PauseTransitionpause = new PauseTransition(Duration.seconds(2));

// Transition 2
RotateTransition rt = new RotateTransition();
rt.setDuration(Duration.seconds(2));
rt.setByAngle(-720);

// Add our translations to a SequentialTransition
SequentialTransition groupTrans = new SequentialTransition();
groupTrans.getChildren().addAll(pt, pause, rt);
groupTrans.setNode(rect);
groupTrans.setCycleCount(2);
...
groupTrans.play();

Dark Mode

Outline