Genuts API

com.genuts.gameui
Class LCDSprite

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

public class LCDSprite
extends ImageSequenceSprite

This sprite is specially designed for games where is has definite positions.

The sprite is represented by its ID, and an array of positions in the playfield.

This sprite has to be used with the LCDCollisionManager. Collision points have to be added by calling the method addCollisionPosition(int, int, int, int) of the collision manager.

The animation should be continous be leaving displayed previous pictures of the sprite. See setContinuity(boolean).

See Also:
LCDCollisionManager.addCollisionPosition(int, int, int, int), setContinuity(boolean)

Constructor Summary
LCDSprite(int id, java.awt.Image seq, int nbh, int nbv, int[][] pos)
          Initializes the sprite, with an sequence image.
 
Method Summary
 boolean checkCollision(Sprite sprite)
          Checks collision position of this sprite with another collision from the other sprite.
 boolean getContinuity()
          Indicates the continuity of pictures from the sequence.
 int getCurrentPosition()
          Gets the current position.
 int[][] getPositions()
          Gets positions for each sequence.
protected  void initContinuity()
          Initializes continuity of pictures from the sequence.
protected  void initPosition()
          Initializes the current X and Y position of the sprite.
 void nextPicture()
          Changes the current displayed picture to the next one.
 void previousPicture()
          Changes the current displayed picture to the previous one.
protected  void removeContinuity()
          Removes continuity of pictures from the sequence.
 void setContinuity(boolean continuous)
          Sets the continuity of pictures from the sequence.
 void setCurrentPictureNumber(int n)
          Sets the current picture position in the sequence.
 void setCurrentPosition(int pos)
          Sets the current position.
 void setHorizontalPicture(int nb)
          Sets the current horizontal picture of the displayed image of the sequence.
protected  void setParent(PlayField parent)
          Sets the parent playfield of this sprite.
 void setPositions(int[][] pos)
          Sets positions for each sequence.
 void setSequence(java.awt.Image seq, int nbh, int nbv)
          Sets the pictures sequence for this sprite.
 void setVerticalPicture(int nb)
          Sets the current vertical picture of the displayed image of the sequence.
 java.lang.String toString()
          Returns a string representation of this LCDSprite.
 
Methods inherited from class com.genuts.gameui.ImageSequenceSprite
getCurrentPictureNumber, getHorizontalPicture, getHorizontalPicturesCount, getPicturesCount, getSequence, getVerticalPicture, getVerticalPicturesCount, isSequenceEnded, isSequenceLoop, paint, sequenceEnded, setSequenceEnded, setSequenceLoop
 
Methods inherited from class com.genuts.gameui.Sprite
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, setPosition, setPremode, setRightCollisionOffset, setSize, setTopCollisionOffset, setVisible, setWrapper, validate
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

LCDSprite

public LCDSprite(int id,
                 java.awt.Image seq,
                 int nbh,
                 int nbv,
                 int[][] pos)
Initializes the sprite, with an sequence image.
The image is composed with all pictures of the sequence.

Parameters:
id - ID of this sprite.
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.
pos - X and Y positions for each sequence.
Method Detail

setPositions

public void setPositions(int[][] pos)
Sets positions for each sequence.

Parameters:
pos - X and Y posotion for each sequence.

getPositions

public int[][] getPositions()
Gets positions for each sequence.

Returns:
X and Y posotion of each sequence.

getCurrentPosition

public int getCurrentPosition()
Gets the current position.
Alias of getCurrentPictureNumber() method from ImageSequenceSprite.

Returns:
The current position of this sprite
See Also:
ImageSequenceSprite.getCurrentPictureNumber()

setCurrentPosition

public void setCurrentPosition(int pos)
Sets the current position.
Alias of setCurrentPictureNumber() method from ImageSequenceSprite.

Parameters:
pos - The new current position of this sprite
See Also:
ImageSequenceSprite.setCurrentPictureNumber(int)

initPosition

protected void initPosition()
Initializes the current X and Y position of the sprite.


setSequence

public void setSequence(java.awt.Image seq,
                        int nbh,
                        int nbv)
Sets the pictures sequence for this sprite.
If the sequence contains only one picture, no sequence is set, but the image of the sprite will be.

Overrides:
setSequence in class ImageSequenceSprite
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.

setHorizontalPicture

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

Overrides:
setHorizontalPicture in class ImageSequenceSprite
Parameters:
nb - the current horizontal picture.

setVerticalPicture

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

Overrides:
setVerticalPicture in class ImageSequenceSprite
Parameters:
nb - the current vertical picture.

setCurrentPictureNumber

public void setCurrentPictureNumber(int n)
Sets the current picture position in the sequence.

Overrides:
setCurrentPictureNumber in class ImageSequenceSprite
Parameters:
n - The current picture position in the sequence.

nextPicture

public void nextPicture()
Description copied from class: ImageSequenceSprite
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.

Overrides:
nextPicture in class ImageSequenceSprite
See Also:
ImageSequenceSprite.sequenceEnded(), ImageSequenceSprite.isSequenceEnded()

previousPicture

public void previousPicture()
Description copied from class: ImageSequenceSprite
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.

Overrides:
previousPicture in class ImageSequenceSprite
See Also:
ImageSequenceSprite.sequenceEnded(), ImageSequenceSprite.isSequenceEnded()

setContinuity

public void setContinuity(boolean continuous)
Sets the continuity of pictures from the sequence.
In other words, for nextPicture() action does the previously displayed pictures has to be erased or not. For previousPicture() action the previously displayed pictures is always erased.

Parameters:
continuous - true to indicate the continuity of th sequence, false otherwise

getContinuity

public boolean getContinuity()
Indicates the continuity of pictures from the sequence.
In other words, for nextPicture() action does the previously displayed pictures has to be erased or not. For previousPicture() action the previously displayed pictures is always erased.

Returns:
true if sequence of pictures is continuous, false otherwise.

setParent

protected void setParent(PlayField parent)
Description copied from class: Sprite
Sets the parent playfield of this sprite.

Overrides:
setParent in class Sprite
Parameters:
parent - Parent playfield of this sprite.

initContinuity

protected void initContinuity()
Initializes continuity of pictures from the sequence.


removeContinuity

protected void removeContinuity()
Removes continuity of pictures from the sequence.


checkCollision

public boolean checkCollision(Sprite sprite)
Checks collision position of this sprite with another collision from the other sprite.

Overrides:
checkCollision in class Sprite
Parameters:
sprite - Sprite to check the collision with
Returns:
true if this sprite and the other sprite are in collision, false otherwise

toString

public java.lang.String toString()
Returns a string representation of this LCDSprite.
The string contains its ID number and its position.

Overrides:
toString in class Sprite

Genuts API

Genuts API