Pro Java 9 Games Development Leveraging the JavaFX APIs

(Michael S) #1
Chapter 10 ■ User InterfaCe DesIgn InteraCtIvIty: event hanDlIng anD ImagIng effeCts

Figure 10-19. Use the Run ➤ Project work process and make sure that the color hue shift matches the rest of
the design


We will code the interior of the scoreButton.setOnAction() event handler when we cover implementing
the scoring engine and high scores UI design later in the book when you have a board game that you can
score in place.
The work process to implement dozens of other special effects in your pro Java 9 game development can
be implemented in much the same way—by declaring a class for the effect you want to utilize, instantiating it
inside of the createSpecialEffects() method, setting parameters for the effect configuration by using methods
from the class, and finally applying the effect to whatever Node object, Control object, ImageView object,
3D object, or Text object that you want by using the .setEffect(effectClassNameHere) method call off of the
object name you’re applying it to.
You will find that the JavaFX special effect package and classes are especially flexible in this
implementation approach, as you can apply all of the popular special effects found in most software
packages to almost any object or Scene Graph Hierarchical structure in JavaFX 9, usually using around a
dozen lines of code and sometimes even fewer.
Once you know how to create and apply these special effects in JavaFX, your pro Java 9 games
development creative power goes up by an order of magnitude. This is because these effects can be applied
anywhere in the Scene Graph hierarchy, as well as anywhere in the 2D, imaging, and 3D rendering pipeline.
I will try to use more of these JavaFX 9 Effect subclasses later during this book as I add more and more
complexity to each chapter and as we progress throughout the book.


Summary


In this tenth chapter, we added interactivity to your user interface design using ActionEvent handling
structures, learned about InputEvent objects and MouseEvent and KeyEvent object processing, and learned
how to apply the special effects contained in the javafx.scene.effects package that leverage the JavaFX
Effect superclass.

Free download pdf