QUICK NAVIGATOR
PRODUCTS
TECHNOLOGIES
DEVELOPMENT TOOLS
* News
* Java Media Framework
* Intel Animation for Java
* Intel Spatial Audio for Java
* Runtime Software License
* SDK Software License
* System Requirements
* Download Area
* Documentation Online
* Gallery
* General FAQ
* Support Information

[INTEL NAVIGATION HEADER]

Intel Animation for Java* Package Tutorial

Lesson 4: Animating Sprites



This applet shows an animating Elvis sprite. Click the "Adjust Current Image" button to animate Elvis once. Click the "Start Animation" to animate Elvis repeatedly. Control the animation speed with the "Faster" and "Slower" buttons.

To create an animated sprite, follow the same steps from the StaticDataSprite Demo, but set the data source of the Sprite to be an ImageSequence instead of a SingleImage. An ImageSequence is a collection of SingleImages.

1. Create an ImageSequence

ImageSequence seq = new ImageSequence(NUM_IMAGES_IN_SEQ, IMAGE_WIDTH, IMAGE_HEIGHT);

(repeat the following four steps for each SingleImage in the ImageSequence)

a. Create an awt.Image

Image image = getImage(getDocumentBase(), "Elvis.gif");

b. Create a SingleImage

SingleImage sequenceItem = new SingleImage(image);

c. Optionally set the transparency color of the SingleImage

sequenceItem.setTransparency(COLOR);

d. Add SingleImage to ImageSequence

seq.setElementAt(sequenceItem, ITEM_INDEX);

2. Create the sprite

StaticDataSprite sprite = new StaticDataSprite();

3. Set the data source of the sprite to be the ImageSequence

sprite.setData(seq);

Animation is done by flipping through the images in the ImageSequence (flipbook-style animation). This is done by calling

sprite.adjustCurrentImageNumber(1);

and then the new image is drawn on the screen by calling

animcanvas.repaint();

The animation speed is controlled by the following code snippet in the run() method:

if ((++count % animDelay) == 0)
{
sprite.adjustCurrentImageNumber(1);
count = 0;
};

where count is initialized to 0 during applet initialization, and animDelay is adjusted to control the animation speed.

This applet actually sets the transparency color to the color of the first pixel in the awt.Image. See the source code for more details.

Previous Lesson Tutorial Contents Next Lesson

View Source

 

This page was last updated on Feb 11th, 1997.

Legal Stuff

Free Web Hosting