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.

Figure 6-1. ImagesTests and image names


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)

cheese

Horizontal/vertical flipping

eyeChart

Progressive blurring

house

Reddening

pumpkin

Zapping (red/yellow pixels)

scooter

Brightening

ufo

Fading

owl

Negation

basn6a16

Resizing

cars

Numbered animation

kaboom

 

cats

 

figure

 

fighter

Named animation

numbers

Callback animation


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.

The application code for this chapter can be found in the ImagesTests/ directory.




Killer Game Programming in Java
Killer Game Programming in Java
ISBN: 0596007302
EAN: 2147483647
Year: 2006
Pages: 340

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net