Pro Java 9 Games Development Leveraging the JavaFX APIs

(Michael S) #1

© Wallace Jackson 2017 369
W. Jackson, Pro Java 9 Games Development, https://doi.org/10.1007/978-1-4842-0973-8_15


CHAPTER 15


3D Gameplay UI Creation:


Using the Sphere Primitive to


Create a UI Node


Now that you have created the multitiered gameBoard Group Node (subclass) hierarchy and tested it to
see whether it rotates as if it were one 3D model, it is time to add a Sphere 3D primitive so we can create a
3D user interface element for the user to use to create random “spins” during gameplay. We will also set
up the Phong shader objects for these and again use GIMP 2.8.22 to create (from scratch) the rest of your
diffuse texture maps for the game board quadrants, as well as a 3D “spinner” UI texture map for a Sphere
primitive. This spinner will be used on each player’s turn to randomly spin the gameboard to select the topic
category. You will always need to differentiate your pro Java 9 game from others out there, so we’ll be unique
and spin the gameboard itself to pick the quadrant (topic category), which cannot be done with real-life
game boards but which can be done with virtual i3D game boards. We’ll add Java 9 code to the top of your
class as well as in the createMaterials(), addNodesToSceneGraph(), and loadImageAssets() method bodies.
We’ll create custom PNG24 diffuse textures to add to your project source (/src) folder. We’ll rearrange your
createGameBoardNodes() method to reorganize the quadrant 3D primitives that we’ll work on during this
chapter to complete the interior parts of the game board design. We’ll place the quadrants together at the
top of this method.
During the chapter, we will also take a look at how you solve problems that you encounter on your way
to creating professional-quality games. In this case, there is a face rendering problem that we encountered
when modeling the game board; it should render smoothly (flat on top) but is rendering with game board
square overlaps that should not be happening. There are also small Y (height) variations that make the
quadrants look depressed once they’re diffuse texture mapped. (Remember the center quadrants looked flat
in Chapter 14 without shaders applied, but they also exhibit these rendering artifacts once we continue to
work on them, which you’ll see later during this chapter.)


Finish Your 3D Assets: Topic Quadrants and Spinner


Let’s continue with the design and development of the 3D components for the board game, including texture
map development using GIMP for the interior of the game board and a 3D spinner UI element used to create
random spins for the game, just like you have in real-life board games. We will do this using Java 9 (JavaFX
API) classes so that we create the game using only the Java 9 APIs and our digital image assets (background
images and texture maps). So far, we have done this in around 400 lines of code! We will add another 10
percent (440) during this chapter to “skin” the quadrants and add a “spinner” UI element located at the top-
left corner of the screen. The first thing we will need to do at the top of the class is to add five more Image

Free download pdf