android.gameengine.icadroids.objects.graphics
Class AnimatedSprite

java.lang.Object
  extended by android.gameengine.icadroids.objects.graphics.Sprite
      extended by android.gameengine.icadroids.objects.graphics.AnimatedSprite

public class AnimatedSprite
extends Sprite

AnimatedSprite is the same as sprite, but has some extra animation functionalities in it. An animatedsprite is a film strip of pictures that will be played after each other. To start animating a sprite, call 'startAnimate()'

Author:
Bas van der Zandt

Field Summary
 
Fields inherited from class android.gameengine.icadroids.objects.graphics.Sprite
loadDelayedSprites, spriteBitmap, spriteHeight, spriteWidth
 
Constructor Summary
AnimatedSprite()
          Make an AnimatedSprite without loading any bitmap in it
AnimatedSprite(java.lang.String resourceName, int numberOfFrames)
          Create an Animated sprite using the specified image and having the specified number of frames.
 
Method Summary
 int getAnimationSpeed()
          Get the animation speed
 int getCurrentFrameNumber()
          Get the current frame number of the animation
 Rect getCurrentFrameRectangle()
          Get the current frame size as rectangle
 int getFrameWidth()
          Get the frame width of this AnimatedSprite
 int getNumberOfFrames()
          Get the number of frames of the sprite
 float getSpriteCenterX()
          Get the middle of the frame, horizontally
 float getSpriteCenterY()
          Get the middle of the frame, vertically
 void initialize()
          Initialize the sprite image.
 void loadAnimatedSprite(java.lang.String resourceName, int numberOfFrames)
          Load a sprite with the given resource.
 void nextFrame()
          Go to the next frame of the animation By default this method will make your animated sprite cycle through all frames.
 void previousFrame()
          Go to the previous frame of the animation
 void setAnimationSpeed(int animationSpeed)
          Set the speed of the animation
 void setFrameNumber(int frameNumber)
          Set the frame number of the animation
 void startAnimate()
          Start animating the sprite
 void stopAnimate()
          Stop animating the sprite
 void updateToNextFrame()
          Method that needs to be called every update of the gameloop.
 
Methods inherited from class android.gameengine.icadroids.objects.graphics.Sprite
calculateSize, getFrameHeight, getSprite, loadSprite, setSprite
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AnimatedSprite

public AnimatedSprite()
Make an AnimatedSprite without loading any bitmap in it


AnimatedSprite

public AnimatedSprite(java.lang.String resourceName,
                      int numberOfFrames)
Create an Animated sprite using the specified image and having the specified number of frames. Sprite images 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. Note: Extremely small sprites don't work well with Collision Detection!

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" .
numberOfFrames - The number of frames in the strip
Method Detail

loadAnimatedSprite

public final void loadAnimatedSprite(java.lang.String resourceName,
                                     int numberOfFrames)
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" .
numberOfFrames - The number of frames in the strip
See Also:
Sprite.loadSprite(java.lang.String)

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)

Overrides:
initialize in class Sprite

updateToNextFrame

public final void updateToNextFrame()
Method that needs to be called every update of the gameloop. GameObjects handle this method by itself!


nextFrame

public final void nextFrame()
Go to the next frame of the animation By default this method will make your animated sprite cycle through all frames. Override this method if you want to create custom animations


previousFrame

public final void previousFrame()
Go to the previous frame of the animation


stopAnimate

public final void stopAnimate()
Stop animating the sprite


setFrameNumber

public final void setFrameNumber(int frameNumber)
Set the frame number of the animation

Parameters:
frameNumber - The frame number to jump to

getCurrentFrameNumber

public final int getCurrentFrameNumber()
Get the current frame number of the animation

Returns:
The current frame number of the animation

getCurrentFrameRectangle

public final Rect getCurrentFrameRectangle()
Get the current frame size as rectangle

Returns:
The current frame size as rectangle

startAnimate

public final void startAnimate()
Start animating the sprite


setAnimationSpeed

public final void setAnimationSpeed(int animationSpeed)
Set the speed of the animation

Parameters:
animationSpeed - How many update must occur before going to the next frame. So when animationSpeed is 3, it takes 3 updates to go to the next frame.

getAnimationSpeed

public int getAnimationSpeed()
Get the animation speed

Returns:
animation speed

getFrameWidth

public final int getFrameWidth()
Get the frame width of this AnimatedSprite

Overrides:
getFrameWidth in class Sprite
Returns:
Sprite width in pixels, returns 0 when no sprite is loaded
See Also:
Sprite.getFrameWidth()

getNumberOfFrames

public int getNumberOfFrames()
Get the number of frames of the sprite

Returns:
The number of frames

getSpriteCenterX

public final float getSpriteCenterX()
Get the middle of the frame, horizontally

Overrides:
getSpriteCenterX in class Sprite
Returns:
Sprite width / 2
See Also:
Sprite.getSpriteCenterX()

getSpriteCenterY

public final float getSpriteCenterY()
Get the middle of the frame, vertically

Overrides:
getSpriteCenterY in class Sprite
Returns:
Sprite height / 2
See Also:
Sprite.getSpriteCenterY()