Game Development Reference
In-Depth Information
Tip
I recommend that you use the
PNG
digital imaging format for your Java 8
games. This is a professional image-
compositing
format, and your games will essen-
tially be a real-time sprite-compositing engine, so you will need to use
PNG32
imagery.
PNG has two truecolor file versions:
PNG24
, which cannot be used in image com-
positing, and
PNG32
, which carries an alpha channel used to define transparency.
I recommend PNG for your games because it has a decent image compression al-
gorithm and because it is a
lossless
image format. This means that PNG has great im-
age quality as well as reasonable levels of data compression efficiency, which will
make your game distribution file smaller. The real power of the PNG32 format lies in
its ability to composite with other game imagery, using
transparency
and
antialiasing
(via its alpha channel).
Digital Image Resolution and Aspect Ratio: Defining
Image Size and Shape
As you probably know, digital imagery is made up of
2D
(two-dimensional)
arrays
of
pixels
(“pixel” stands for
picture
[pix]
element
[el]). The sharpness of an image is ex-
pressed by its
resolution
, which is the number of pixels in the image
width
(or
W
,
sometimes referred to as the
x axis
) and
height
(or
H
, sometimes referred to as the
y
axis
) dimensions. The more pixels an image has, the higher its resolution. This is simil-
ar to how digital cameras work, as the more megapixels in an image capture device
(called a camera CCD), the higher the image quality that can be achieved.
To find the total number of image pixels,
multiply
the width pixels by the height
pixels. For instance, a wide video graphics array (VGA) 800 × 480 image contains
384,000 pixels, which is exactly three-eighths of a megabyte. This is how you would
find the
size
of your image, both in terms of kilobytes (or megabytes) used and height
and width on the display screen.
The shape of a digital image asset is specified using the image
aspect ratio
. Aspect
ratio is the
width:height
ratio for the digital image and defines the square (
1:1
aspect
ratio) or rectangular (also known as
widescreen
) digital image shape. Displays featur-
ing a
2:1
(widescreen) aspect ratio, such as
2,160 × 1,080
resolution, are now available.
A
1:1 aspect ratio
display (or image) is always
perfectly square
, as is a
2:2
or
3:3
aspect ratio image. You might see this aspect ratio on a smart watch, for instance. It is
important to note that it is the
ratio
between these two width and height (x and y) vari-
ables that defines the shape of an image or screen, not the actual numbers themselves.