Genuts API

com.genuts.gameui
Class ImageSequenceSprite

java.lang.Object
  |
  +--com.genuts.gameui.Sprite
        |
        +--com.genuts.gameui.ImageSequenceSprite
Direct Known Subclasses:
AnimatedSprite, LCDSimplePictureSprite, LCDSprite

public class ImageSequenceSprite
extends Sprite

This sprite is a sequence of pictures from one image. It gives an easy way to display next picture or previous picture.

The image sequence 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, we can use this image:
Number of pictures horizontally: 4
Number of pictures vertically: 3
and instanciate :

 Sprite sprite = new ImageSequenceSprite(image, 4, 3);
 

The sequence of pictures can loop, and provides a cyclic continuation of pictures. Otherwise, the sprite can be advise if the sequence ended.

See Also:
setSequenceLoop(boolean), sequenceEnded(), isSequenceEnded()

Constructor Summary
ImageSequenceSprite(java.awt.Image seq, int nbh, int nbv)
          Initializes the sprite, with a sequence image.
 
Method Summary
 int getCurrentPictureNumber()
          Gets the current picture index in the image sequence.
 int getHorizontalPicture()
          Returns the current horizontal index of the displayed picture in the image.
 int getHorizontalPicturesCount()
          Gets the number of pictures contained horizontally in the sequence image.
 int getPicturesCount()
          Gets the number of pictures contained in the sequence image.
 java.awt.Image getSequence()
          Gets the sequence image for this sprite.
 int getVerticalPicture()
          Returns the current vertical index of the displayed picture in the image.
 int getVerticalPicturesCount()
          Gets the number of pictures contained vertically in the sequence image.
 boolean isSequenceEnded()
          Indicates that the sequence loop ended.
 boolean isSequenceLoop()
          Is the sequence loops continously or stop on the last image?
 void nextPicture()
          Changes the current displayed picture to the next one.
 void paint(java.awt.Graphics g)
          Draws the current picture for this sprite.
 void previousPicture()
          Changes the current displayed picture to the previous one.
protected  void sequenceEnded()
          Indicates that the sequence ended.
 void setCurrentPictureNumber(int n)
          Sets the current picture position in the image sequence.
 void setHorizontalPicture(int nb)
          Sets the current horizontal index of the displayed picture in the image.
 void setSequence(java.awt.Image seq, int nbh, int nbv)
          Sets the pictures seqeunce for this sprite.
protected  void setSequenceEnded(boolean end)
          Sets if the sequence loop ended.
 void setSequenceLoop(boolean v)
          Sets if the sequence loops or stop on the last image.
 void setVerticalPicture(int nb)
          Sets the current vertical index of the displayed picture in the image.
 
Methods inherited from class com.genuts.gameui.Sprite
checkCollision, collisionWith, getActionSprite, getBackground, getBottomCollisionOffset, getBounds, getFinalActionSprite, getFinalWrapper, getHeight, getId, getImage, getLeftCollisionOffset, getParent, getPosition, getRightCollisionOffset, getSize, getTopCollisionOffset, getWidth, getWrapper, getX, getY, invalidate, isBackgroundSprite, isPremode, isSpriteAt, isValidate, isVisible, preCollisionWith, repaint, setBackground, setBackgroundSprite, setBottomCollisionOffset, setBounds, 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

ImageSequenceSprite

public ImageSequenceSprite(java.awt.Image seq,
                           int nbh,
                           int nbv)
Initializes the sprite, with a sequence image.
The image is composed with all pictures of the sequence.

Parameters:
seq - An image containing all pictures of the sequence
nbh - Horizontaly number of pictures in the image
nbv - Verticaly number of pictures in the image
Method Detail

getSequence

public java.awt.Image getSequence()
Gets the sequence image for this sprite.

Returns:
An image containing all pictures of the sequence.

getPicturesCount

public int getPicturesCount()
Gets the number of pictures contained in the sequence image.

Returns:
The total number of pictures contained in the sequence image.

getHorizontalPicturesCount

public int getHorizontalPicturesCount()
Gets the number of pictures contained horizontally in the sequence image.

Returns:
The number of pictures contained horizontally in the sequence image.

getVerticalPicturesCount

public int getVerticalPicturesCount()
Gets the number of pictures contained vertically in the sequence image.

Returns:
The number of pictures contained vertically in the sequence image.

setSequence

public void setSequence(java.awt.Image seq,
                        int nbh,
                        int nbv)
Sets the pictures seqeunce for this sprite.
If the sequence contains only one picture, no sequence will be set, and the sprite will have the image has background.

The current picture number is inchanged, except it is greater than the new number of pictures, in that case, it is placed to the last picture.

Parameters:
seq - An image containing all pictures of the sequence.
nbh - Horizontaly number of pictures in the image.
nbv - Verticaly number of pictures in the image.
Throws:
java.lang.IllegalAccessError - if nbh or nbv is equal to 0.

isSequenceLoop

public boolean isSequenceLoop()
Is the sequence loops continously or stop on the last image?
When the sequence stops, a call to the method sequenceEnded() is performed.

Returns:
true if the sequence loops, false otherwise.
See Also:
sequenceEnded(), isSequenceEnded()

setSequenceLoop

public void setSequenceLoop(boolean v)
Sets if the sequence loops or stop on the last image.

Parameters:
v - true if the sequence loops, false otherwise.

getHorizontalPicture

public int getHorizontalPicture()
Returns the current horizontal index of the displayed picture in the image.

Returns:
the current horizontal picture.

setHorizontalPicture

public void setHorizontalPicture(int nb)
Sets the current horizontal index of the displayed picture in the image.

Parameters:
nb - the current horizontal picture.

getVerticalPicture

public int getVerticalPicture()
Returns the current vertical index of the displayed picture in the image.

Returns:
the current vertical picture.

setVerticalPicture

public void setVerticalPicture(int nb)
Sets the current vertical index of the displayed picture in the image.

Parameters:
nb - the current vertical picture.

getCurrentPictureNumber

public int getCurrentPictureNumber()
Gets the current picture index in the image sequence.
i.e. The index of the displayed picture, consider the top left picture has the index 0.

Returns:
The current picture index in the image sequence.

setCurrentPictureNumber

public void setCurrentPictureNumber(int n)
Sets the current picture position in the image sequence.
i.e. The index of the displayed picture, consider the top left picture has the index 0.

Parameters:
n - The current picture position in the image sequence.

nextPicture

public void nextPicture()
Changes the current displayed picture to the next one.
If the current picture is the last one, and if isSequenceLoop() is set to false, the sequence will not loop to the first picture and a call to sequenceEnded() will be performed, otherwise the sequence will be loop.

See Also:
sequenceEnded(), isSequenceEnded()

previousPicture

public void previousPicture()
Changes the current displayed picture to the previous one.
If the current picture is the first one, and if isSequenceLoop() is set to false the sequence will not loop to the last picture and a call to sequenceEnded() will be performed, otherwise the sequence will be loop.

See Also:
sequenceEnded(), isSequenceEnded()

isSequenceEnded

public boolean isSequenceEnded()
Indicates that the sequence loop ended.
This method is called only if the sprite doesn't loop.

Returns:
true if the sequence ended, false otherwise.

setSequenceEnded

protected void setSequenceEnded(boolean end)
Sets if the sequence loop ended.

Parameters:
end - true if the sequence end, false otherwise.

sequenceEnded

protected void sequenceEnded()
Indicates that the sequence ended.
This method is called only at the end of the sequence (at the beginning or the end) and if the sprite doesn't loop.


paint

public void paint(java.awt.Graphics g)
Draws the current picture for this sprite.

Overrides:
paint in class Sprite
Parameters:
g - The graphics context to use for painting.

Genuts API

Genuts API