Pro Java 9 Games Development Leveraging the JavaFX APIs

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

a4Button.setText("Answer Four");
a4Button.setFont(Font.font("Arial Black", 30 ));
a4Button.setMaxSize(350, 100);
a4Button.setTranslateY(180);


Let’s utilize a Run ➤ Project work process one last time before we write the code to actually implement
this new Q&A UI in the rest of our JavaFXGame code. We will need to hide this StackPane and child Button
objects until it is needed to display answer options to the player. We’ll also need to display this StackPane at
the end of your camera animation, which will tilt and zoom your camera into the game board, changing the
camera angle and distance, which may change how the StackPane and Button objects render and therefore
necessitate “tweaking” to size and position settings. After we finish implementing this StackPane and Button
objects’ Q&A UI design inside the start() method and createAnimationAssets() method, we can return
to the previous code and tweak the numeric values to fine-tune how it looks in the top-down “game board
question and answer view.”
As you can see in Figure 21-14, the font family and font size used on these Button UI objects make
a huge difference in readability from Figure 21-12. The only problem I can see is that the panel is a bit too
tall, with a bit too much space around the edges and between Button UI elements, which we’ll address
later after we implement this Q&A UI deeper in the Java code that we’ve written already. Remember, game
development is an iterative process!


Figure 21-13. Add the setFont(Font.font(“Arial Black”, 30)) method call to each Button after the setText()
method call

Free download pdf