Pro Java 9 Games Development Leveraging the JavaFX APIs

(Michael S) #1
Chapter 10 ■ User InterfaCe DesIgn InteraCtIvIty: event hanDlIng anD ImagIng effeCts

Since the Java code is in the right order inside of the methods, I suspect that the order the methods
are called in is most likely the source of this problem. Let’s take a look at the order of the method
calls inside of the start() method, shown at the top of Figure 10-9. Notice that createSpecialEffects() is
called after createTextAssets(), and yet we’re using the .setEffect(dropShadow) method call inside of
the createTextAssets() method, so we have to move the createSpecialEffects() method call above the
createTextAssets() method call, as shown in Figure 10-13, so your effect is set up before you utilize it. Java
code is pretty logical if you trace that logic through the process of what you’re doing!
As you can see in Figure 10-16, this solved the problem, and your drop shadow effect is rendering
correctly.
The next modification you will need to make is to your legalButton.setOnAction() event-handling
structure to make everything on the screen a nice shade of purple. This can be achieved by color shifting the
hue of your logo 40 percent, this time in the negative direction around the color wheel. Using floating-point
numbers, the right positive 180 degrees of a color wheel ranges from 0.0 to 1.0, and the left negative side
ranges from 0.0 to -1.0.
The Java code for your legalButton event-handling Java statements is shown, highlighted, at the bottom
of Figure 10-15. It should look like the following Java code:


legalButton.setOnAction(new EventHandler() {
@Override
public void handle(ActionEvent event) {
infoOverlay.getChildren().clear();
infoOverlay.getChildren().addAll(copyText, riteText);
infoOverlay.setTranslateY( 200 );
infoOverlay.setTranslateY( 370 );
uiLayout.setBackground(Background.EMPTY);
boardGameBackPlate.setImage(legalLayer);
logoLayer.setEffect(colorAdjust);
colorAdjust.setHue(-0.4);
}
} );

Free download pdf