28.04.2019 Views

[JAVA][Beginning Java 8 Games Development]

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Chapter 5 ■ An Introduction to Game Design: Concepts, Multimedia, and Using Scene Builder<br />

Also, note that you can set the percentage of dithering that is used. I often select either the 0 percent or<br />

100 percent setting; however, you can fine-tune the dithering effect anywhere between these two extreme values.<br />

You can also choose between dithering algorithms, because, as you probably have surmised, the dithering effect is<br />

created using dithering algorithms, which are part of the indexed file format (in this case, PNG8) compression routines.<br />

I use diffusion dithering, which gives a smooth effect along irregularly shaped gradients, as is seen in the car<br />

fender. You can also use a noise option, which is more randomized, or a pattern option, which is less so. The diffusion<br />

option usually gives the best results, which is why I choose it when I am using indexed color (which is not often).<br />

Dithering, as you might imagine, adds data patterns to an image that are more difficult to compress. This is<br />

because smooth areas in an image, such as gradients, are easier for the compression algorithm to compress than<br />

sharp transitions (edges) or random pixel patterns (e.g., dithering or “noise” from a camera CCD).<br />

Therefore, applying the dithering option will always increase the data footprint by a few percentage points. Be<br />

sure to check the resulting file size with and without dithering applied (selected in the Export dialog) to see if it is<br />

worth the improved visual result that it affords. Note that there is also a transparency option (check box) for indexed<br />

color PNG images but that the alpha channel used in PNG8 images is only 1 bit (on/off), not 8 bit, as with PNG32.<br />

You can also increase the data footprint of your image by adding an alpha channel to define transparency for<br />

compositing. This is because by adding an alpha channel you will be adding in another 8-bit color channel (or a<br />

transparency channel, actually) to the image being compressed. If you need an alpha channel to define transparency<br />

for your image to support future compositing requirements, such as using the image as a game sprite, there is not<br />

much choice but to include the alpha channel data.<br />

If your alpha channel contains all zeroes (or uses an all-black fill color), which would define your imagery as<br />

being completely transparent, or contains all FF values (or uses an all-white fill color), which would define your image<br />

as being completely opaque, you would essentially (in practical terms) be defining an alpha that does not contain any<br />

useful alpha data values. The transparent image would therefore need to be removed, and the opaque image would<br />

need to be defined as a PNG24 rather than a PNG32.<br />

Finally, most alpha channels that are used to mask objects in the RGB layers of the digital image should compress<br />

very well. This is because the alpha channel is primarily areas of white (opaque) and black (transparent), with some<br />

medium-gray values along the edge between the two colors to antialias the mask (see Figure 5-2). These gray areas<br />

contain the antialiasing values in the alpha channel, and will provide the visually smooth-edge transitions between<br />

the object in the RGB layers of the image and any background color or background images that may be used behind it.<br />

The reason for this is that in the alpha channel image mask, an 8-bit transparency gradient (from white to<br />

black) defines levels of transparency, which could be thought of as per-pixel blending (opacity) strength. Therefore,<br />

the medium-gray values on the edges of each object in the mask (which is contained in the alpha channel) will serve<br />

essentially to average the colors of the object edge, and any target background, no matter what color (or image) value<br />

it may contain. This offers real-time antialiasing with any target background that may be used, including animated<br />

backgrounds.<br />

Digital Video and Animation: Frames, Rate, Looping, Direction<br />

Interestingly, all the concepts that I have just covered for digital images apply equally well to digital video and<br />

animation, as both formats use digital images as the foundation for their content. Digital video and animation extend<br />

digital imaging into the fourth dimension (time) by using frames. The two formats are composed of an ordered<br />

sequence of frames, which are displayed rapidly over time.<br />

The term “frame” comes from the film industry, in which, even today, frames of film are run through film<br />

projectors at a rate of 24 frames per second (24FPS), which creates the illusion of motion. Because both digital video<br />

and animation are made up of a collection of frames containing digital images, the concept of frame rate, expressed<br />

as frames per second, is also very important when it comes to the memory data footprint optimization work process<br />

(for animation assets) as well as the digital video file size data footprint optimization work process. As discussed<br />

previously, in <strong>Java</strong>FX this attribute for animation is stored in the Animation object rate variable (see Chapter 4).<br />

www.it-ebooks.info<br />

113

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!