Pro Java 9 Games Development Leveraging the JavaFX APIs

(Michael S) #1
Chapter 21 ■ Questions and answers: Finishing the setup Methods and digital audio

Use cut and paste to move the createQAnodes() method up to after the createAnimationAssets()
method call, as shown in Figure 21-5. Add your qaLayout StackPane object to the declaration at the top
of your class, making it a compound statement. Then instantiate the qaLayout StackPane inside of the
createQAnodes() method and configure it to be at a -250 and -425 X, Y location using the setTranslate()
methods. Also, set a Color.WHITE background color and set a 400x500 preferred size for the StackPane
using the setPrefSize() method call, as shown highlighted in Figure 21-5.


The Java 9 code, shown in Figure 21-5, should look like the following Java 9 statements once you are
done:


StackPane uiLayout, qaLayout; // Declaration at the top of the JavaFXGame class
...
qaLayout = new StackPane(); // Statements inside of the createQAnodes() method body
qaLayout.setTranslateX(-250);
qaLayout.setTranslateY(-425);
qaLayout.setBackground(new Background(new BackgroundFill(Color.WHITE, CornerRadii.EMPTY,
Insets.EMPTY) ) );
qaLayout.setPrefSize(400, 500);


Before we can render the i3D scene to see our initial Q&A layout result (which will eventually
be fine-tuned), we will need to add the qaLayout StackPane to your SceneGraph root object in the
addNodesToSceneGraph() method using the getChildren().addAll() method chain. Otherwise, it will not
show up in the rendering used in Run ➤ Project.
Also notice that this qaLayout StackPane needs to be placed into the second position (of your four top-
level node branches now included in this new SceneGraph hierarchy) so that it is in front of the gameBoard
3D game board model and behind the uiLayout user interface StackPane and the 3D spinner game board
spin Sphere 3D UI element.
This addition is shown in the following Java 9 code statement and highlighted in light blue and yellow in
the middle of Figure 21-6:


root.getChildren().addAll(gameBoard, qaLayout, uiLayout, spinner);


Figure 21-5. Declare and instantiate a qaLayout object and configure it for location, color, and size in
createQAnodes()

Free download pdf