Motorola J2ME Specifications Page 56

  • Download
  • Add to my manuals
  • Print
  • Page
    / 86
  • Table of contents
  • BOOKMARKS
  • Rated. / 5. Based on customer reviews
Page view 55
Animation Frames
An animated sprite is created from an image divided into sections as described in the
constructor Sprite(Image, int, int). The individual sections of the image are considered the
raw frames of the
Sprite. The method getNumRawFrames returns the number of raw
frames.
Sprite Drawing
Sprites can be drawn at anytime using the draw(Graphics) method. The sprite
will be drawn on the
Graphics object, according to the current state information
maintained by the Sprite (i.e. position, frame, visibility). Some potential uses of Sprites
include:
Arbitrarily draw the Sprite on a
GameScreen.
A Sprite can be added to a
PlayField. Then PlayField.draw(Graphics, int, int) will
automatically draw all the Sprites associated with the
PlayField.
draw(Graphics) could be called from the
paint() method in a subclass of
Canvas.
draw(Graphics) could be called at any time to draw the
Sprite on a MIDP mutable
image. This is virtually identical to the first bullet, drawing on a
GameScreen.
Only in the case where a set of Sprites are a part of a container object (i.e. where the
Sprite is associated with a PlayField) is the depth information automatically
handled by the system. In other situations, managing the drawing order is the
responsibility of the developer.
Sprite Constructor
The Sprite class defines the following constructors:
public Sprite(Image img) – Creates a new non-animated
Sprite
from an
Image object. All animation operations on a non-animated Sprite behave as
if there is a single raw frame. At construction time, the
Sprite's position will be set
to (0,0), the depth will be set to 0, and the Sprite will be visible. The Sprite shall
behave as if the image used in creation were cached. If a mutable image is used to
create the Sprite, the Sprite's appearance should not reflect changes to mutable
source image.
public Sprite(Image img, int fWidth, int fHeight)
Creates a new animated
Sprite from an Image. The constructor parameters are
the following:
img - Image to use for Sprite;
fWidth - width, in pixels, of the individual raw frames;
fHeight - height, in pixels, of the individual raw frames.
Page view 55
1 2 ... 51 52 53 54 55 56 57 58 59 60 61 ... 85 86

Comments to this Manuals

No comments