Pro Java 9 Games Development Leveraging the JavaFX APIs

(Michael S) #1
Chapter 14 ■ 3D MoDel hierarChy Creation: Using priMitives to Create a gaMe BoarD

for Image objects named diffuse1 through diffuse 20 and Shader1 through Shader 20, in anticipation of the
code we are about to write. Cut and paste the PhongMaterial code to “live” in createMaterials() and delete
the specular attributes. The code, shown in Figure 14-13, should look like the following:


Image diffuse1 ... diffuse20; // Object Declarations at top of class
PhongMaterial Shader1 ... Shader20;
...
Shader1 = new PhongMaterial(Color.WHITE); // Create Diffuse Shader in createMaterials()
Shader1.setDiffuseMap(diffuse1);


Next, let’s remove all the special effects map-related code in loadImageAssets() that we created in
Chapter 13 , except for diffuseMap, which you will rename diffuse1. Copy and paste the diffuse1 instantiation
four times, and reference the next four game board square texture maps, gameboardsquare2.png through
gameboardsquare5.png.
You’re now ready, from a shader standpoint, to construct the first quadrant of your game board. You
should now have five (diffuseMap) Image objects, named diffuse1 through diffuse5, in the last half of your
loadImageAssets() method. These will hold the diffuseMap property texture maps defining where the warm
colors (red, orange, yellow) will be mapped onto your game board squares that are the children of quadrant
(1) for the game board, which we will lay out first. We’ll lay out the green quadrant second and then the blue
and purple quadrants last.
These first five of the (eventual) 24 diffuse color texture map (diffuseMap property) Image objects
should be added using the following Java statements, which are highlighted at the bottom of Figure 14-14:


diffuse 1 = new Image("/gameboardsquare.png", 256, 256, true, true, true);
diffuse 2 = new Image("/gameboardsquare 2 .png", 256, 256, true, true, true);
diffuse 3 = new Image("/gameboardsquare 3 .png", 256, 256, true, true, true);
diffuse 4 = new Image("/gameboardsquare 4 .png", 256, 256, true, true, true);
diffuse 5 = new Image("/gameboardsquare 5 .png", 256, 256, true, true, true);


Figure 14-13. Add Image object declarations diffuse1 through diffuse20 and create a createMaterials() shader
method

Free download pdf