Pro Java 9 Games Development Leveraging the JavaFX APIs

(Michael S) #1

Chapter 2 ■ an IntroduCtIon to Content CreatIon: 2d new MedIa asset FundaMentals


The eight hexadecimal data slots for an ARGB value will hold data with the following format:
0xAARRGGBB. Thus, for Color.WHITE, all alpha, red, green, and blue channels in the hexadecimal color
data value representation would be at their maximum luminosity (or opacity), and the alpha channel is fully
opaque, that is, not transparent, as represented by an FF value. Therefore, a 32-bit hexadecimal value for the
Color.WHITE constant would be 0xFFFFFFFF.
A 100 percent transparent alpha channel can be represented by the alpha slot being set to zero, creating
a “clear” image. Therefore, you would represent transparent image pixel values using any data value
between 0x00000000 and 0x00FFFFFF. It is important to note that if an alpha channel value equates to this
full transparency level, then it would follow that the 16,777,216 color values that will be contained in the
other six (RGB) hexadecimal data value slots will not matter whatsoever, because that pixel will be evaluated
as not being there, as it is transparent and, thus, will not be composited in the final image or animation
composite image, so its color is moot (does not matter at all).


Digital Image Object Masking: Using Alpha Channels to Composite


Game Sprites


One of the primary applications for alpha channels in game design is to mask out areas of an image or an
animation (an image series) so that it can be utilized as a game sprite in a gameplay image compositing
scenario. Masking is the process of “cutting” subject matter out of a digital image so that it can be placed on
its own layer using alpha channel transparency values. This is done using a digital imaging software package,
as shown in Figure 2-2.
Digital image compositing software packages such as Photoshop or GIMP feature tools that are
included for use in masking and image compositing. You can’t do effective image compositing without doing
effective masking, so this is an important area to master for game designers who want to integrate graphics
elements, such as image sprites and sprite animation, into their game designs. The art of digital image
masking has been around for a very long time!
Masking can be done for you automatically, using professional bluescreen (or greenscreen) backdrops
along with computer software that can automatically extract those exact color values to create a mask. This
mask is turned into alpha channel (transparency) information (data). Masking can also be done manually by
hand, by using digital image software, by using one of the algorithmic selection tools in conjunction with
various sharpening and blur algorithms.
We’ll learn a lot about this work process during the course of this book using common open source
software packages such as GIMP. Masking can be a complex and involved work process, and a complete
mastery of this process may need to span a couple of chapters, instead of trying to fit it all into one single
chapter in the book (this one). This chapter is to expose you to foundational knowledge of the work
processes we undertake during the book.
A key consideration for the masking process is getting smooth, sharp edges around a masked object
(subject matter). This is so that when you place a masked object (in the case of this book, it would be a game
sprite) into (over) new background imagery, it will look to a game player like it was photographed there in
the first place (like it is in the video).
The key to doing this successfully lies in the pixel selection work process, which involves using digital
image software selection tools such as the scissors tool in GIMP or the magic wand tool in Photoshop.
These must be used in the proper fashion (order) to be completely effective. Using the correct selection work
process is critical!
For instance, if there are areas of uniform color around the object that you want to mask (maybe
you shot it against a bluescreen), you’ll use a magic wand tool with a proper threshold setting to select
everything except your object. Then you invert the selection, which will give you a selection set containing
the object. Often the correct work process involves approaching something in reverse. Other selection tools
contain complex algorithms that can look at color changes between pixels. These can be useful for edge
detection, which we can use for other selection methods.

Free download pdf