Images are a central part of every game, and this chapter examines how we can (efficiently) load and display them, apply visual effects such as blurring, fading, and rotation, and animate them. The ImagesTests application is shown in Figure 6-1. The screenshot includes the name of the images for ease of reference later. Figure 6-1. ImagesTests and image names
The images (in GIF, JPEG, or PNG format) are loaded by my own ImagesLoader class from a JAR file containing the application and the images. The images are loaded using ImageIO's read( ), and stored as BufferedImage objects, to take advantage of the JVM's "managed image" features. ImagesLoader can load individual images, image strips, and multiple image files that represent an animation sequence. The animation effects utilized by ImagesTests fall into two categories:
Table 6-1 lists the image names against the visual effect they demonstrate.
The effects are mostly implemented with Java 2D operations, such as convolution or affine transformation. Occasionally, I make use of capabilities in drawImage( ), e.g., for resizing and flipping an image. The majority of the images are GIFs with a transparent background; balls.jpg is the only JPEG. The PNG files are: owl.png, pumpkin.png, basn6a08.png, and basn6a16.png. The latter two use translucency, and come from the PNG suite maintained by Willem van Schaik at http://www.schaik.com/pngsuite/pngsuite.html. I've utilized several images from the excellent SpriteLib sprite library by Ari Feldman, available at http://www.arifeldman.com/games/spritelib.html, notably for the cats, kaboom, cars, and fighter animations.
|