Genuts ME API

com.genuts.gameui
Class AnimatedSprite

java.lang.Object
  extended bycom.genuts.gameui.Sprite
      extended bycom.genuts.gameui.ImageSequenceSprite
          extended bycom.genuts.gameui.AnimatedSprite
All Implemented Interfaces:
Tickable
Direct Known Subclasses:
SimpleAnimationSprite

public class AnimatedSprite
extends ImageSequenceSprite
implements Tickable

This sprite is an animation of pictures in one image. Its goal is to provide an object with animated picture along the time with a sequence of pictures.

The image is composed of ordered picture for the left to the rigtht, and from the top to bottom. All pictures have the same size.

For example, if want to have this animation:

we have to use this image:

Number of pictures horizontally: 4
Number of pictures vertically: 3
and instanciate :

 Sprite sprite = new AnimatedSprite(image, 4, 3, 5);
 

See Also:
ImageSequenceSprite

Constructor Summary
AnimatedSprite(Image anim, int nbh, int nbv, int frequence)
          Initializes the sprite, with an animation image.
 
Method Summary
 void animate(int ticks)
          Animates the sprite as desired.
 int getCurrentRemindTick()
          Gets the number of ticks to way before the next picture will be displayed.
 int getFrequence()
          Returns the number of ticks to wait between two pictures of the animation.
 boolean isPaused()
          Gets pause state for this animated sprite.
 void setCurrentRemindTick(int v)
          Sets the number of ticks to way before the next picture will be displayed.
 void setFrequence(int freq)
          Sets the number of ticks to wait between two pictures of the animation.
 void setPause(boolean pause)
          Sets pause state for this animated sprite.
 void tick(int ticks)
          Receives a tick from the playfield to animate picture.
 
Methods inherited from class com.genuts.gameui.ImageSequenceSprite
getCurrentPictureNumber, getHorizontalPicture, getHorizontalPicturesCount, getPicturesCount, getSequence, getVerticalPicture, getVerticalPicturesCount, isSequenceEnded, isSequenceLoop, nextPicture, paint, previousPicture, sequenceEnded, setCurrentPictureNumber, setHorizontalPicture, setSequence, setSequenceEnded, setSequenceLoop, setVerticalPicture
 
Methods inherited from class com.genuts.gameui.Sprite
checkCollision, collisionWith, getActionSprite, getBackground, getBottomCollisionOffset, getFinalActionSprite, getFinalWrapper, getHeight, getId, getImage, getLeftCollisionOffset, getParent, getRightCollisionOffset, getTopCollisionOffset, getWidth, getWrapper, getX, getY, invalidate, isBackgroundSprite, isPremode, isSpriteAt, isValidate, isVisible, preCollisionWith, repaint, setBackground, setBackgroundSprite, setBottomCollisionOffset, setBounds, setId, setImage, setLeftCollisionOffset, setParent, setPosition, setPremode, setRightCollisionOffset, setSize, setTopCollisionOffset, setVisible, setWrapper, toString, validate
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

AnimatedSprite

public AnimatedSprite(Image anim,
                      int nbh,
                      int nbv,
                      int frequence)
Initializes the sprite, with an animation image.
The image is composed with all pictures of the animation.

Parameters:
anim - An image containing all pictures of the animation.
nbh - Horizontaly number of pictures in the image.
nbv - Verticaly number of pictures in the image.
frequence - Number of ticks to wait between two pictures of the animation, or -1 if the picture doesn't change.
Method Detail

getFrequence

public int getFrequence()
Returns the number of ticks to wait between two pictures of the animation.

Returns:
The number of ticks to wait between two pictures of the animation, or -1 if the picture doesn't change

setFrequence

public void setFrequence(int freq)
Sets the number of ticks to wait between two pictures of the animation.

Parameters:
freq - The number of ticks to wait between two pictures of the animation, or -1 if the picture doesn't change.

getCurrentRemindTick

public int getCurrentRemindTick()
Gets the number of ticks to way before the next picture will be displayed.

Returns:
Number of ticks to way before the next picture will be displayed.

setCurrentRemindTick

public void setCurrentRemindTick(int v)
Sets the number of ticks to way before the next picture will be displayed.

Parameters:
v - Number of ticks to way before the next picture will be displayed.

setPause

public void setPause(boolean pause)
Sets pause state for this animated sprite.

Parameters:
pause - true to set the animated sprite in pause state, false otherwise.

isPaused

public boolean isPaused()
Gets pause state for this animated sprite.

Returns:
true to set the animated sprite in pause state, false otherwise.

tick

public void tick(int ticks)
Receives a tick from the playfield to animate picture.

If getCurrentRemindTick() is equal to 0, next picture is displayed.
There is no animation if getFrequence() is equal to -1.

Specified by:
tick in interface Tickable
Parameters:
ticks - Number of ticks from the playfield

animate

public void animate(int ticks)
Animates the sprite as desired. By default, it moves to the next picture.

Parameters:
ticks - Number of ticks from the playfield

Genuts ME API

Genuts ME API