Chapter 6. Image Loading, Visual Effects, and Animation

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.

ImagesTests and image names

Figure 6-1. ImagesTests and image names

Tip

An image name is the filename of the image, minus its extension.

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:

  • Those defined by repeatedly applying a visual effect, such as blurring, to the same image but by an increasing amount

  • Those where the animation is represented by a series of different images displayed one after another

Table 6-1 lists the image names against the visual effect they demonstrate.

Table 6-1. Images names and their visual effects

Image name

Visual effect

atomic

Rotation

balls basn6a08

Mixed colors

bee

Teleportation (uneven fading) ...

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.