Java Reference
In-Depth Information
■
even though the starting value of the opacity was set to 0, you still need to set the
fromValue
property of the
transition to 0 explicitly for it to work correctly in reverse.
Note
The last step is to add in the event listeners that will fire when the user mouses over the
Node
. These can be added
by calling the
addEventHandler
method with a lambda expression that accepts
MouseEvents
:
addEventHandler(MouseEvent.MOUSE_ENTERED_TARGET, t -> {
if (model.legalMove(x, y).get()) {
highlightTransition.setRate(1);
highlightTransition.play();
}
});
addEventHandler(MouseEvent.MOUSE_EXITED_TARGET, t -> {
highlightTransition.setRate(-1);
highlightTransition.play();
});
Notice that the code plays the same animation in either case, but changes the rate of the animation based on
whether it should be played forwards (1) or backwards (-1). This ensures that the animation will seamlessly transition
even if it is in progress.
When run, the Reversi application now animates a subtle blue outline over the highlighted
Node
under the cursor,
as shown in Figure
5-16
.
Figure 5-16.
The Reversi application with a highlight animation over the active cell
Search WWH ::
Custom Search