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 3: Moving Sprites



This applet shows an Elvis sprite that can be moved. Clicking the buttons cause Elvis to move left and right. When Elvis reaches the edge of the screen, the Floor and Background move.

The following needs to be done to move a sprite:

1. Get the position of the sprite (see Notes on Coordinate System below)

Point3D pos = sprite.getPosition(sprite);

2. Adjust the position

pos.x = pos.x + DELTA_X;

3. Set the position of the sprite

sprite.setPosition(pos);

4. Draw the repositioned sprite on the screen

animcanvas.repaint();

Notes on Coordinate System
When you call getPosition or setPosition, 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.
Previous Lesson Tutorial Contents Next Lesson

View Source

 

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

Legal Stuff

Free Web Hosting