Pro Java 9 Games Development Leveraging the JavaFX APIs

(Michael S) #1

Chapter 11 ■ 3D SCene Configuration: uSing the perSpeCtiveCamera anD pointLight


This Java code is shown here, as well as being highlighted in blue near the middle of Figure 11-3:

uiLayout = new StackPane();
uiLayout.setTranslateX( 0 );
uiLayout.setTranslateY( 0 );


Notice in Figure 11-3 that you are using .setTranslateX() and .setTranslateY() on your logoLayer
ImageView, as well as on your infoOverlay TextFlow, each of which retain their positioning relative to your
uiLayout StackPane.
This preservation of relative positioning is because of the parent-child relationships that you have
established in your SceneGraph hierarchy, which is why this is a powerful scene construction tool for any
type of Scene whether it’s i2D, i3D, or hybrid. This will also be very important as we develop the i3D portion
of your pro Java 9 game during this book, as we will need to do even more integral transformations in the 3D
portion of your gameplay than simply centering your UI control panel in front of the camera so that it blocks
the view of the 3D game (at least for now; we may change this UI design later as we continue to refine the
Java code and the game design). This is exactly how game design, and coding, transpires in real life; game
development is a journey, not a destination.
Use a Run ➤ Project work process to see whether we’re getting closer to synchronizing your 2D UI
overlay with the 3D scene behind it. As you can see in Figure 11-4, the UI panel is now in the center of your
screen, albeit scaled down. Therefore, we will continue to refine our object attributes. Next, we will use the
camera object’s Z translation variable to bring the camera closer in to the 3D scene in order to achieve our
desired end result.


Figure 11-3. Add the .setTranslateX() and .setTranslateY() method calls off the uiLayout StackPane object,
both set to zero

Free download pdf