Pro Java 9 Games Development Leveraging the JavaFX APIs

(Michael S) #1
Chapter 19 ■ Game Content enGine: ai LoGiC with random Content SeLeCtion methodS

Use a Run ➤ Project work process, and click the spinner UI multiple times to test the code thoroughly.
What you should see is that each time the game board lands on a correct quadrant, as is specified in the
NetBeans 9 Output Pane, the game board squares will populate the correct quadrant with animal imagery,
as shown in Figure 19-16.


Note that the texture map colors and orientation do not yet match up with each quadrant’s color
scheme and orientation, but then again, you can use this rendering preview to show you what you need
to do to make this happen when you are working in GIMP, which I showed you how to do in the previous
Chapter 18 on game content.


Texture Map Management: Coding a resetTextureMaps() Method


As you can tell from Figure 19-16, the next programming task at hand is to code the method that will reset
the game board to its default (empty) state before the next spin animation begins. This is done by setting the
diffuse color map digital image references back to their default files by re-instantiating the Image objects
with the new image asset reference (there is currently no setImageReference() method call, although there
should be). This will force Java 9 to garbage collect (to re-allocate) the previously referenced image in
memory and to replace it with the new image data referenced. You also have to reference the associated
Shader object, in the next line of code, to re-insert the Shader object into memory, with the new reference
data pointing to the new Image object just loaded into memory. Since we will always be using your default
(blank) texture maps, this can all be in one resetTextureMaps() method, which does not change but which,
when called, resets your 3D game board squares to their default unpopulated (with digital image topic or
question content) state, before each subsequent random game board spin begins (that is, before the rest of
the statements in your if(pressed == spinner) conditional if() construct are processed).


Figure 19-16. All the angle spin evaluations are now correct, eventually filling all Shaders with texture map
image data

Free download pdf