Pro Java 9 Games Development Leveraging the JavaFX APIs

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

Unused alpha channels will therefore need to be removed, and an opaque image would need to be defined
as a PNG24 rather than a PNG32 to save on the data footprint.
Finally, most alpha channels that are used to mask objects that are in the RGB layers of the digital image
should compress very well. This is because they are largely areas of white (opaque) and black (transparent)
with some medium gray values along the edges between the two colors to anti-alias your mask (see Figure 2-2).
These gray areas that contain the anti-aliasing transparency values in the alpha channel, which will always
provide you with visually smooth edge transitions, between the object in the RGB layers of the image, and
any background color or background images that might be used behind it. Essentially, anti-aliasing in
the alpha channel provides you with real-time compositing for the object that the alpha channel serves
because you could put video behind it, in the background plate, and the alpha anti-aliasing will in real time
guarantee a smooth edge result with different edge color blending on every single frame of the video.
The reason for this is that since your alpha channel image mask uses an 8-bit transparency gradient,
ranging from white to black and defining levels of transparency rather than color, this should be thought
of as per-pixel blending, or opacity strength value. Therefore, the medium gray values, on the edges of
each object in a mask that is contained in the alpha channel, will serve to essentially average the colors of
your object’s edges and any target background, no matter what color value, image asset, illustration asset,
animation asset, or video asset that a background plate might contain.
This provides real-time anti-aliasing with any target background that might be used, even if your object
is a static object, because the anti-aliasing provided by your alpha channel will even work using animated
backgrounds.


Digital Video or Animation: Frames, Frame Rate, Loops,


Direction


It is interesting to note that all the concepts that we have just covered for digital images apply equally as
well to digital video and 2D animation since both of these fourth-dimensional (time-based) new media
formats use digital images as a foundation for their content. Digital video, as well as 2D animation, extends
digital imaging into the fourth dimension of time by introducing something called frames. Digital video and
animation are comprised of an ordered sequence of frames, which are displayed rapidly over time to create
the illusion of movement, bringing imagery alive.
The term frame comes from the film industry where even today film frames are run through film
projectors, at a frame rate of 24 frames per second (typically abbreviated as 24 FPS). This creates the
illusion of motion. Since both digital video and animation are made up of a collection of frames containing
digital imagery, this concept of frame rate, expressed as frames per second, is also very important when it
comes to both the memory data footprint optimization work process (for animation assets) and the digital
video file size data footprint optimization work process. In JavaFX, as you will soon learn, this attribute for
animation is stored in the Animation object’s rate variable.
The optimization concept regarding frames in an Animation object or digital video asset is very similar
to the optimization concept regarding pixels in the image (the resolution of a digital image); the fewer used,
the better! This is because the number of frames used in an animation or video multiplies both the system
memory used and the file size data footprint with each frame that is used. In digital video, not only does
each frame’s (image) resolution greatly impact the file size, but so does the number of frames per second, or
frame rate, that is specified in the compression settings dialog. Earlier in this chapter, we learned that if we
multiply the number of pixels in the image by its number of color channels, we’ll get the raw data footprint
for the image. With animation or digital video, we will now multiply that number again by the total number
of frames that will need to be utilized in order to create an illusion of motion.
Therefore, if we have an animated VGA (RGB) background plate for our game (remember that each
frame is 900KB) that uses five frames to create the illusion of motion, we are using 900KB times five, or
4500KB (or 4.5MB), of system memory to hold that animation. Of course, this is too much memory to use
for a background, which is why we will be using static backgrounds with sprite overlays to achieve this same

Free download pdf