Pro Java 9 Games Development Leveraging the JavaFX APIs

(Michael S) #1
Chapter 2 ■ an IntroduCtIon to Content CreatIon: 2d new MedIa asset FundaMentals

PNG6 uses half as many as that (64), PNG5 uses half as many as that (32), PNG 4 would therefore use 16,
PNG3 would use 8, PNG2 would use 4, and PNG1 would use 2, or black and white (on or off ). Generally, you
will want to use the full 256 colors, because JavaFX only supports PNG8, PNG4, or PNG1, so use PNG8 if you
are going to use indexed color imagery at all.
Common color depths used in the digital imaging industry include 8-bit, 16-bit, 24-bit, and 32-bit. I’ll
outline the common ones here, along with their formats. The lowest color depth exists in 8-bit indexed
color images. These feature a maximum of 256 color values and use GIF and PNG8 image formats to hold
this indexed color type of data.
A medium color depth image will feature 16-bit color depths and will thus contain 65,536 colors
(calculated as 256 times 256) and is supported by the TARGA (TGA) and Tagged Image File Format (TIFF)
digital image formats. If you want to use digital image formats other than GIF, JPEG, and PNG in your Java 8
games, import the ImageJ library.
True-color color depth images will feature the 24-bit color depth and will thus contain more than
16 million colors. This is calculated as 256 times 256 times 256 and equals 16,777,216 colors. File formats
supporting 24-bit color depth include JPEG (or JPG), PNG, BMP, XCF, PSD, TGA, TIFF, and WebP. JavaFX
supports three of these: JPEG, PNG24 (24-bit), and PNG32 (32-bit). Using the true-color depth 24-bit or
32-bit imagery will give you the highest level of quality. This is why I have been recommending that you use
the PNG24 or PNG32 formats for your Java 9 games and IoT projects.
Next, let’s take a look at how we represent image transparency, by using the PNG32 image’s alpha
channel.


Digital Image Compositing: Using Alpha Channels and Transparency


with Layers


Next let’s take a look at how to define digital image pixel transparency values using alpha channels and
how these can be used for compositing digital imagery in real time for your Java game. Compositing is the
process of seamlessly blending together more than one layer of digital imagery. As you might well imagine,
this is an extremely important concept for game design and development. Compositing is useful when you
want to create an image on the display that appears as though it is one single image (or animation) but is
actually the seamless collection of (more than one) composited image layers. One of the principal reasons
you would want to set up an image or animation composite is to allow programmatic control over various
elements in those images, by having each element on a different layer.
To accomplish this, you need to have an alpha channel transparency value, which you can utilize to
precisely control the blending of that pixel with the pixel in the same X,Y image location on other layers that
are underneath it. In digital imaging software, transparency values for each image layer are represented by
using a checkerboard pattern, which you can see on the right side of Figure 2-2.

Free download pdf