Pro Java 9 Games Development Leveraging the JavaFX APIs

(Michael S) #1

Chapter 10 ■ User InterfaCe DesIgn InteraCtIvIty: event hanDlIng anD ImagIng effeCts


Another popular and useful special effect that you will want to use in your pro Java 9 games
development is adjusting pixel color value. There’s a powerful ColorAdjust special effect class in the javafx.
scene.effect package that allows developers to adjust digital imaging attributes for images, including
contrast using .setContrast(), brightness using .setBrightness(), saturation using .setSaturation(), and hue
(color) using .setHue(). Let’s learn about this next.


Color Adjust: Adjusting Hue, Saturation, Contrast, and Lightness


Let’s use the .setHue() method call off of a ColorAdjust object to allow us to “color shift” the color
temperature of our PNG32 transparent logo digital image asset so that it will match up visually with the color
of all of your other screen design element color values for each of the Button Control user interface designs
we are refining during this chapter. Declare a ColorAdjust object named colorAdjust at the top of your class.
Inside of your createSpecialEffects() method, instantiate the object using the ColorAdjust() constructor and
then call a .setHue() method off this object using a floating-point 0.4 value to color shift the current image
color value 40 percent of the way (forward) around the color wheel. The Java code, which is highlighted in
the middle and bottom of Figure 10-12, would look like the following:


DropShadow dropShadow;
ColorAdjust colorAdjust;
...
private void createSpecialEffects() {
dropShadow = new DropShadow();
dropShadow.setRadius(4.0);
dropShadow.setOffsetX(3.0);
dropShadow.setOffsetY(3.0);
dropShadow.setColor(Color.DARKGRAY);
colorAdjust = new ColorAdjust();
colorAdjust.setHue(0.4); }


Figure 10-12. Add a colorAdjust object instantiation and use a .setHue(0.4) method call off of the object to
configure it

Free download pdf