android.gameengine.icadroids.objects.graphics
Class Sprite

java.lang.Object
  extended by android.gameengine.icadroids.objects.graphics.Sprite
Direct Known Subclasses:
AnimatedSprite

public class Sprite
extends java.lang.Object

Sprite holds and handles correct loading of images (bitmaps), and includes some useful methods for getting information about the image.

Author:
Bas van der Zandt

Field Summary
static java.util.Vector<Sprite> loadDelayedSprites
           
protected  Bitmap spriteBitmap
          The bitmap that the sprite uses
protected  int spriteHeight
          The height in pixels of the sprite
protected  int spriteWidth
          The width in pixels of the sprite
 
Constructor Summary
Sprite()
          Make a Sprite without loading any bitmap in it
Sprite(java.lang.String resourceName)
          Load a sprite with the given resource Sprites must be stored in the res/drawable folders of your Android project.
 
Method Summary
protected  void calculateSize(Bitmap sprite)
          Calculate the size of the sprite.
 int getFrameHeight()
          Get the height of the sprite
 int getFrameWidth()
          Get the width of the sprite
 Bitmap getSprite()
          Get the sprite in Bitmap.
 float getSpriteCenterX()
          Get the center width of the sprite
 float getSpriteCenterY()
          Get the center height of the sprite
 void initialize()
          Initialize the sprite image.
 void loadSprite(java.lang.String resourceName)
          Load the given resource in the sprite object Sprites must be stored in the res/drawable folders of your Android project.
 void setSprite(Bitmap sprite)
          Load a bitmap into a sprite Note: bitmaps are already loaded images, when you want to load a resource that hasn't been loaded yet, use 'loadSprite()'
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

spriteBitmap

protected Bitmap spriteBitmap
The bitmap that the sprite uses


spriteWidth

protected int spriteWidth
The width in pixels of the sprite


spriteHeight

protected int spriteHeight
The height in pixels of the sprite


loadDelayedSprites

public static java.util.Vector<Sprite> loadDelayedSprites
Constructor Detail

Sprite

public Sprite()
Make a Sprite without loading any bitmap in it


Sprite

public Sprite(java.lang.String resourceName)
Load a sprite with the given resource Sprites must be stored in the res/drawable folders of your Android project. If you have only one image, store it in the 'nodpi' folder. If you have various versions (hi-res and lo-res) for rendering on devices of varying screen sizes, use the lo- & hi-dpi folders.

Parameters:
resourceName - The name of the resource in the /res/drawable folder without extension , so when your picture in the /res/drawable is named 'picture.jpg', this parameter should be 'picture' .
Method Detail

loadSprite

public void loadSprite(java.lang.String resourceName)
Load the given resource in the sprite object Sprites must be stored in the res/drawable folders of your Android project. If you have only one image, store it in the 'nodpi' folder. If you have various versions (hi-res and lo-res) for rendering on devices of varying screen sizes, use the lo- & hi-dpi folders.

Parameters:
resourceName - The name of the resource in the /res/drawable folder without extension , so when your picture in the /res/drawable is named 'picture.jpg', this parameter should be 'picture' .

initialize

public void initialize()
Initialize the sprite image.
Note: Don't call this yourself. This method is automatically called by the GameEngine when loading of the sprite has been postponed. (In the Android Activity lifecycle, sprites can only be loaded after a certain point, or an error will be thrown. The GameEngine postpones loading until after this point)


calculateSize

protected final void calculateSize(Bitmap sprite)
Calculate the size of the sprite. Throws a null pointer exception when no sprite is loaded.

Parameters:
sprite - The bitmap that needs to be calculated

getSprite

public final Bitmap getSprite()
Get the sprite in Bitmap. Throws a null pointer exception when no sprite is loaded

Returns:
The sprite in bitmap

getFrameWidth

public int getFrameWidth()
Get the width of the sprite

Returns:
Sprite width in pixels, returns 0 when no sprite is loaded

getFrameHeight

public final int getFrameHeight()
Get the height of the sprite

Returns:
Sprite height in pixels, returns 0 when no sprite is loaded

setSprite

public final void setSprite(Bitmap sprite)
Load a bitmap into a sprite Note: bitmaps are already loaded images, when you want to load a resource that hasn't been loaded yet, use 'loadSprite()'

Parameters:
sprite - The bitmap that need to be loaded

getSpriteCenterX

public float getSpriteCenterX()
Get the center width of the sprite

Returns:
Sprite width / 2

getSpriteCenterY

public float getSpriteCenterY()
Get the center height of the sprite

Returns:
Sprite height / 2