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 2: Using StaticDataSprites 



This applet shows four Sprites. Sprites are the building blocks of an animation display. Every visible object in an animation display is a sprite. This applet uses four StaticDataSprites: the sky, the buildings, the floor, and Elvis. (There are two types of Sprites: StaticDataSprites and DynamicDataSprites. DynamicDataSprites and the difference between the two types of Sprites will be discussed later.)

The following needs to be done to create a Sprite:

1. Create an awt.Image

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

2. Create a SingleImage

SingleImage spriteSource = new SingleImage(image);

3. Optionally set the transparency color of the SingleImage (see Notes on Transparency Color)

spriteSource.setTransparency(COLOR);

4. Create the sprite

StaticDataSprite sprite = new StaticDataSprite();

5. Assign the SingleImage to the sprite

sprite.setData(spriteSource);

6. Set the destination of the sprite to a surface

sprite.setDestination(animCanvas.getSurface());

7. Position the sprite on the surface (see Notes on Coordinate System below)

sprite.setPosition(new Point3D(x, y, z));

8. Repaint the animCanvas (which causes all the sprites to be drawn in the right order)

animcanvas.repaint();

Notes on Transparency
SingleImages support transparency color, in which a user-definable color is displayed as transparent. Clicking the buttons above clear the transparency color (so there is no transparency color) or set the transparency color.

Notes on Coordinate System
When you call getPosition or setPosition (discussed later), the Point3D describes the location of the top, left corner of the sprite on the surface. This Point3D is on the coordinate system of the surface.

Coordinate systems in Intel Animation for Java have the following characteristics:

  • the origin is at the top left corner
  • the x coordinate increases toward the right
  • the y coordinate increases downward
  • the z coordinate represents depth. Sprites that have a lower z are drawn last, or over the sprites with a higher z. In this applet, Elvis has z = 200 and the floor has a z = 300, so Elvis is drawn after the floor (Elvis appears to have been drawn over the floor).
  • x and y can have negative values. z CANNOT have a negative value.

This applet 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