Pro Java 9 Games Development Leveraging the JavaFX APIs

(Michael S) #1
Chapter 11 ■ 3D SCene Configuration: uSing the perSpeCtiveCamera anD pointLight

Next, use the Run ➤ Project work process to see whether you’ve accomplished the visual objective of
synchronizing your StackPane Node branch and its children with the 3D camera object’s projection plane.
As you can see in Figure 11-8, your UI screen looks great and the buttons are working.


Before we get into learning about the LightBase (superclass) object and the AmbientLight and PointLight
subclasses, let’s make sure all of our other previous 2D UI code is still working and doing what we want it to do.
When adding a major feature or change to your Java 9 code, it is always important to take the time to do this.


StackPane UI Testing: Making Sure Everything Else Still Works


Click the Game Rules Button, shown in Figure 11-8, and make sure the UI screen for your game instructions
is still readable and professional in appearance, even though we are going to refine this UI further, before
the game is published. As you can see in Figure 11-9, the Instructions screen in indeed still readable;
however, the Color.WHITE background color has been replaced with Color.BLACK since we set our new 3D
Scene object to use this for its Fill Color value, as shown in Figure 11-1, using a scene.setFill(Color.BLA
CK); Java statement. This means that we need to now set the Background Color value for our StackPane to
Color.WHITE to fill our UI screen with a white color somewhere farther up in the scene compositing (now
rendering) pipeline. Since the StackPane is above the Scene and below the VBox, ImageView, and TextFlow,
this is the logical object to set to a Color.WHITE Background Fill color. This will involve placing only one
Java statement in the three active Button event handling structures located in the .start() method, rather than
changing dozens of Java statements relating to setting Text object Color and DropShadow attributes, not
to mention lightening the ImageView using the .setLightness() method call to brighten the heading image
text elements. This will also give me a chance to show you how to get around the limitation of the StackPane
object (class) not having a .setFill() method, which means we have to create a complex method chain with
two nested “object instantiation inside of a method” Java constructs, where we create a new Background
object and a new BackgroundFill object inside of a .setBackground(Background) method call and configure
the BackgroundFill to white.


Figure 11-8. Use Run ➤ Project to see that your StackPane is perfectly synchronized (visually) with the
camera projection plane

Free download pdf