Loading Images
The ImagesLoader
class can load four different formats of images, which I call o
, n
, s
, and g
images. The images are assumed to be in a local JAR file in a subdirectory Images/ below ImagesLoader
. They are loaded as BufferedImage
s using ImageIO
's read()
, so they can become managed images.
The typical way of using an ImagesLoader
object is to supply it with a configuration file containing the filenames of the images that should be loaded before game play
Figure 6-2. Class diagrams for ImagesTests
begins. However, it is possible to call ImagesLoader
's load methods at any time during execution.
Here is the imsInfo.txt configuration file used in ImagesTests
:
// imsInfo.txt images o atomic.gif o balls.jpg o bee.gif o cheese.gif o eyeChart.gif o house.gif o pumpkin.png o scooter.gif o ufo.gif o owl.png n numbers*.gif 6 n figure*.gif 9 g fighter left.gif right.gif still.gif up.gif s cars.gif 8 s cats.gif 6 s kaboom.gif 6 o basn6a08.png o basn6a16.png
Blank lines, and lines beginning with //
, are ignored by the loader. The syntax for the four image formats is:
o <fnm> n <fnm*.ext> <number> s <fnm> <number> g <name> <fnm> [ <fnm> ]*
An o
line causes a single filename, called <fnm>
, to be loaded from Images/.
A n
line loads a series of numbered image files, whose filenames use the numbers 0-<number>-1 in place of the *
character in the filename. For example:
n numbers*.gif 6
This indicates ...
Get Killer Game Programming in Java now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.