J2ME Polish
J2ME Polish 2.4 Documentation
Enough Software

SpriteItem

Use the SpriteItem for showing an animated javax.microedition.lcdui.game.Sprite in your Form.

Design


You can only design basic concepts like background, padding, etc with a SpriteItem:

Programming

For creating a SpriteItem you have to create a Sprite first:

Image image = null;
try {
	image = Image.createImage( "/sprite.png");
	int frameWidth = 30;
	int frameHeight = 30;
	this.sprite = new Sprite( image, frameWidth, frameHeight );
	//#style sprite
	this.spriteItem = new SpriteItem( null, this.sprite, 200, 0, false );
	this.spriteItem.addCommand( this.cmdStartGame );
	this.spriteItem.setItemCommandListener( this );
} catch (IOException e) {
	//#debug error
	System.out.println( "Unable to load /sprite.png" + e );
}

The SpriteItem constructor accepts the following parameters:

	SpriteItem(String label, Sprite sprite, long animationInterval, int defaultFrameIndex, boolean repeatAnimation )
  • String label: the label
  • Sprite sprit: the sprite that should be painted
  • long animationInterval: the interval in milliseconds for animating this item
  • int defaultFrameIndex: the frame that is shown when the SpriteItem is not focused
  • boolean repeatAnimation: defines whether the animation should be repeated when the last frame of the frame sequence has been reached.

You can set the animation sequence on the Sprite itself. Thanks to J2ME Polish' gaming API you can use Sprite on MIDP 1.0 devices as well.

JavaDoc

back to top