Pro Java 9 Games Development Leveraging the JavaFX APIs

(Michael S) #1

Chapter 10 ■ User InterfaCe DesIgn InteraCtIvIty: event hanDlIng anD ImagIng effeCts


You may be wondering why I set Hue to 40 percent (again) when I did this already in the
createSpecialEffects() method. The reason for this is that the setting in the createSpecialEffects() method
could be viewed to be a “default” setting, and the reason I have to specify it (again) in the helpButton event
handler code is that other Button handlers will set different Hue values. Your helpButton.setOnAction()
event-handling code should now look like the following:


helpButton.setOnAction(new EventHandler() {
@Override
public void handle(ActionEvent event) {
infoOverlay.getChildren().clear();
infoOverlay.getChildren().addAll(helpText, cardText);
infoOverlay.setTranslateX( 130 );
infoOverlay.setTranslateY( 360 );
uiLayout.setBackground(Background.EMPTY);
boardGameBackPlate.setImage(helpLayer);
logoLayer.setEffect(colorAdjust);
colorAdjust.setHue(0.4);
}
});


Now it’s time to use the Run ➤ Project work process and make sure the drop shadow effect on
the TextFlow object is making your Text objects more readable and matches the drop shadow on the
screen caption image. You can see in Figure 10-14 that something is amiss in the Java code, as the JavaFX
application runs but is not drop shadowing the text. Let’s check the order our Java code is executing our
statements in to see if there is something out of order!


Figure 10-14. Declare and instantiate a ColorAdjust object named colorAdjust and use .setHue() to shift the
color 40 percent

Free download pdf