Game Development Reference
In-Depth Information
nel capability to show through (via alpha channel transparency values) in certain pixel
locations in the image composite.
How do digital image alpha channels, and the concept of image compositing, factor
into Java game design? The primary advantage is an ability to break the game play
screen, and the sprites, projectiles, and background graphic elements that it includes,
into a number of
component layers.
The reason for doing this is to be able to apply
Java 8 programming logic (or JavaFX classes) to individual graphic image elements to
control parts of your game play screen that you would not otherwise be able to control
individually were it one single image.
Another part of image compositing, called
blending modes
, also factors heavily in-
to professional image-compositing capabilities. JavaFX blending modes are applied by
using the
Blend
class with the
BlendMode
constant values found in the
javafx.scene.effect
subpackage (see
Chapter 4
). This JavaFX blending effect package
gives Java game developers many of the same image-compositing modes that Pho-
toshop (and GIMP) afford to a digital imaging artisan. This turns Java 8 (via JavaFX)
into a powerful image-compositing engine, just like Photoshop, and the blending al-
gorithms are controllable at a very flexible level, using custom Java 8 code. JavaFX
blending mode constants include
ADD
,
SCREEN
,
OVERLAY
,
DARKEN
,
LIGHTEN
,
MULTIPLY
,
DIFFERENCE
,
EXCLUSION
,
SRC_ATOP
,
SRC_OVER
,
SOFT_LIGHT
,
HARD_LIGHT
,
COLOR_BURN
, and
COLOR_DODGE
.
Representing Color and Alpha in Java 8 Game Code:
Using Hexadecimal Notation
Now that you know what color depth and alpha channels are, and that color and trans-
parency are represented by using a combination of four different
image channels
(al-
pha, red, green, and blue [ARGB]) within any given digital image, it is important to un-
derstand how, as programmers, you are supposed to represent these four ARGB image
color and transparency channel values in Java 8 and JavaFX.
In the Java programming language, color and alpha are used not only in 2D digital
imagery (commonly referred to as
bitmap
imagery), but also in 2D illustration (com-
monly referred to as
vector
imagery). Colors and transparency values are also often
used across a number of different color setting options. As you have already seen with
the Stage object and the Scene object, you can set a background color (or transparency
value) for a stage, scene, layout container (StackPane), or UI control, among other
things.