Using transitions – the predefined animations
Transitions are helper classes to simplify the most common animations:
- Movement
- Size change
- Rotation
- Color change
Using movement and resize transitions
Moving objects is a definition of an animation. So it's only logical to start from movement transitions:
TranslateTransition
: Plain movePathTransition
: Moving along the pathRotateTransition
: Rotating objectsScaleTransition
: Changing objects' size
Using TranslateTransition
The most straightforward transition isTranslateTransition
. You choose what and where to move using thetranslateX
andtranslateY
properties and callplay()
. For example, if we look at theTimeline
from the start of this chapter:
KeyValue keyValue = new KeyValue(node.translateXProperty(), 200); KeyFrame keyFrame = new KeyFrame(Duration.seconds(5), keyValue); Timeline timeline = new Timeline(keyFrame);
Using TranslateTransition
, it will look as follows (you can compare similar parameters marked by the bold text):
// chapter5/transitions/TranslateTransitionDemo...