Genuts ME API

com.genuts.gameui
Class SpriteWrapper

java.lang.Object
  extended bycom.genuts.gameui.Sprite
      extended bycom.genuts.gameui.SpriteWrapper
All Implemented Interfaces:
Tickable
Direct Known Subclasses:
MovingSpriteWrapper, TraceSpriteWrapper

public abstract class SpriteWrapper
extends Sprite
implements Tickable

This Sprite is a special sprite, its goal is only to wrap another Sprite Object.
In that way, you can have multiple behavior without any high developpement procedure, and the same wrapper can be used by diffenrent type of sprites.

A sprite on which a sprite wrapper interact is called an action sprite.

A SpriteWrapper is an abstract super class, because there are no sense to instanciate this class directly.

The only thing to know is that when you add a Sprite to its playfield, don't forget to pass the reference of the wrapper and not of the sprite.


Constructor Summary
SpriteWrapper()
          Initializes a default wrapper sprite.
SpriteWrapper(Sprite sprite)
          Initializes the wrapper sprite.
 
Method Summary
 boolean checkCollision(Sprite sprite)
          Checks collision of the action sprite with another action sprite or with the edges of the playfield.
protected  void collisionWith(Sprite s)
          Propagations of the collision event to the action event.
 Sprite getActionSprite()
          Returns the action sprite.
 int getBackground()
          Gets the background color of the action sprite.
 int getBottomCollisionOffset()
          Gets the offset on the bottom side for which the collision must not be considered.
 Sprite getFinalActionSprite()
          Returns the first action sprite contained in this sprite that is not a SpriteWrapper.
 int getHeight()
          Gets the height of the action sprite.
 int getId()
          Gets the id of the action sprite.
 Image getImage()
          Gets the image of the action sprite.
 int getLeftCollisionOffset()
          Gets the offset on the left side for which the collision must not be considered.
 PlayField getParent()
          Gets the parent playfield of the action sprite.
 int getRightCollisionOffset()
          Gets the offset on the right side for which the collision must not be considered.
 int getTopCollisionOffset()
          Gets the offset on the top side for which the collision must not be considered.
 int getWidth()
          Gets the width of the action sprite.
 int getX()
          Gets the X coordinate of the action sprite.
 int getY()
          Gets the Y coordinate of the action sprite.
 void invalidate()
          Invalidates the action sprite.
 boolean isBackgroundSprite()
          Is the action sprite a part of the background?
 boolean isPremode()
          Returns the pre-collision mode state for the action sprite.
 boolean isSpriteAt(int x, int y)
          Indicates if the action sprite is under (x,y) coordinates.
 boolean isValidate()
          Indicates if the action sprite as been valideted by its parent.
 boolean isVisible()
          Is the action sprite visible?
 void paint(Graphics g)
          Paints the action sprite.
protected  boolean preCollisionWith(Sprite s)
          Propagations of the pre-collision event to the action event.
 void repaint()
          Repaints the action component.
 void setActionSprite(Sprite sprite)
          Sets the action sprite.
 void setBackground(int color)
          Sets the background color for the action sprite.
 void setBackgroundSprite(boolean v)
          Sets if the action sprite a part of the background.
 void setBottomCollisionOffset(int offset)
          Sets the offset on the bottom side for which the collision must not be considered.
 boolean setBounds(int x, int y, int width, int height)
          Moves and resizes this action sprite to conform to the new bounding rectangle.
 void setId(int id)
          Sets the action sprite's id.
 void setImage(Image img)
          Sets the image for the action sprite.
 void setLeftCollisionOffset(int offset)
          Sets the offset on the left side for which the collision must not be considered.
protected  void setParent(PlayField parent)
          Sets the parent playfield of the action sprite.
 boolean setPosition(int x, int y)
          Sets the position of the action sprite in the playfield.
 void setPremode(boolean state)
          Sets the pre-collision mode for the action sprite.
 void setRightCollisionOffset(int offset)
          Sets the offset on the right side for which the collision must not be considered.
 boolean setSize(int w, int h)
          Sets the size of the action sprite.
 void setTopCollisionOffset(int offset)
          Sets the offset on the top side for which the collision must not be considered.
 void setVisible(boolean v)
          Sets if the action sprite is visible.
 void tick(int ticks)
          Propagations of the tick event to the action event if it is an instance of Tickable.
 void validate()
          Validates the action sprite by its parent.
 
Methods inherited from class com.genuts.gameui.Sprite
getFinalWrapper, getWrapper, setWrapper, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

SpriteWrapper

public SpriteWrapper()
Initializes a default wrapper sprite.


SpriteWrapper

public SpriteWrapper(Sprite sprite)
Initializes the wrapper sprite.

Parameters:
sprite - Sprite which really acts.
Method Detail

getFinalActionSprite

public Sprite getFinalActionSprite()
Description copied from class: Sprite
Returns the first action sprite contained in this sprite that is not a SpriteWrapper.
i.e. Search the first sprite that is not a SpriteWrapper.

Overrides:
getFinalActionSprite in class Sprite
Returns:
The First action sprite that is not a SpriteWrapper.

getActionSprite

public Sprite getActionSprite()
Returns the action sprite.

Overrides:
getActionSprite in class Sprite
Returns:
The action sprite.

setActionSprite

public void setActionSprite(Sprite sprite)
Sets the action sprite.
The parent playfield of the old action sprite is set to null.
The parent playfield of the new action sprite is set to the same one as the sprite wrapper.

Parameters:
sprite - Action sprite.

setId

public void setId(int id)
Sets the action sprite's id.
The id is usefull to make difference between sprites for collisions.

Overrides:
setId in class Sprite
Parameters:
id - ID of this sprite

getId

public int getId()
Gets the id of the action sprite.
The id is usefull to make difference between sprites for collisions.

Overrides:
getId in class Sprite
Returns:
The ID of this sprite

setSize

public boolean setSize(int w,
                       int h)
Sets the size of the action sprite.

Overrides:
setSize in class Sprite
Returns:
true if the modification was done, false otherwise.

setPosition

public boolean setPosition(int x,
                           int y)
Sets the position of the action sprite in the playfield.

Overrides:
setPosition in class Sprite
Parameters:
x - X position of the sprite.
y - Y position of the sprite.
Returns:
true if the modification was done, false otherwise.

getX

public int getX()
Gets the X coordinate of the action sprite.

Overrides:
getX in class Sprite
Returns:
The X coordinate of the sprite.

getY

public int getY()
Gets the Y coordinate of the action sprite.

Overrides:
getY in class Sprite
Returns:
The Y coordinate of the sprite.

getWidth

public int getWidth()
Gets the width of the action sprite.

Overrides:
getWidth in class Sprite
Returns:
The width of the sprite.

getHeight

public int getHeight()
Gets the height of the action sprite.

Overrides:
getHeight in class Sprite
Returns:
The height of the sprite.

setBounds

public boolean setBounds(int x,
                         int y,
                         int width,
                         int height)
Moves and resizes this action sprite to conform to the new bounding rectangle.

Overrides:
setBounds in class Sprite
Parameters:
x - X position of the sprite.
y - Y position of the sprite.
width - width of the sprite.
height - height of the sprite.
Returns:
true if the modification was done, false otherwise.

isSpriteAt

public boolean isSpriteAt(int x,
                          int y)
Indicates if the action sprite is under (x,y) coordinates.
(x,y) coordinates are located in this sprite. by default it checks if (x,y) are in the bounding box of the sprite.

Overrides:
isSpriteAt in class Sprite
Parameters:
x - X coordinate in the sprite to check.
y - Y coordinate in the sprite to check.
Returns:
true if this sprite is under (x,y) coordinates, false otherwise.

setPremode

public void setPremode(boolean state)
Sets the pre-collision mode for the action sprite.

Overrides:
setPremode in class Sprite
Parameters:
state - true to set the pre-collision mode to true, false otherwise.
See Also:
Sprite.setPremode(boolean)

isPremode

public boolean isPremode()
Returns the pre-collision mode state for the action sprite.

Overrides:
isPremode in class Sprite
Returns:
true if the pre-collision mode is true, false otherwise.

checkCollision

public boolean checkCollision(Sprite sprite)
Checks collision of the action sprite with another action sprite or with the edges of the playfield.

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.

getRightCollisionOffset

public int getRightCollisionOffset()
Gets the offset on the right side for which the collision must not be considered.

Overrides:
getRightCollisionOffset in class Sprite
Returns:
The offset on the right side for which the collision must not be considered.

setRightCollisionOffset

public void setRightCollisionOffset(int offset)
Sets the offset on the right side for which the collision must not be considered.

Overrides:
setRightCollisionOffset in class Sprite

getLeftCollisionOffset

public int getLeftCollisionOffset()
Gets the offset on the left side for which the collision must not be considered.

Overrides:
getLeftCollisionOffset in class Sprite
Returns:
The offset on the left side for which the collision must not be considered.

setLeftCollisionOffset

public void setLeftCollisionOffset(int offset)
Sets the offset on the left side for which the collision must not be considered.

Overrides:
setLeftCollisionOffset in class Sprite

getTopCollisionOffset

public int getTopCollisionOffset()
Gets the offset on the top side for which the collision must not be considered.

Overrides:
getTopCollisionOffset in class Sprite
Returns:
The offset on the top side for which the collision must not be considered.

setTopCollisionOffset

public void setTopCollisionOffset(int offset)
Sets the offset on the top side for which the collision must not be considered.

Overrides:
setTopCollisionOffset in class Sprite

getBottomCollisionOffset

public int getBottomCollisionOffset()
Gets the offset on the bottom side for which the collision must not be considered.

Overrides:
getBottomCollisionOffset in class Sprite
Returns:
The offset on the bottom side for which the collision must not be considered.

setBottomCollisionOffset

public void setBottomCollisionOffset(int offset)
Sets the offset on the bottom side for which the collision must not be considered.

Overrides:
setBottomCollisionOffset in class Sprite

isValidate

public boolean isValidate()
Indicates if the action sprite as been valideted by its parent.

Overrides:
isValidate in class Sprite
Returns:
true if this parent as valid it, false otherwise.

validate

public void validate()
Validates the action sprite by its parent.

Overrides:
validate in class Sprite

invalidate

public void invalidate()
Invalidates the action sprite.

Overrides:
invalidate in class Sprite

isBackgroundSprite

public boolean isBackgroundSprite()
Is the action sprite a part of the background?

Overrides:
isBackgroundSprite in class Sprite
Returns:
true if this sprite is a part of the background, false otherwise.

setBackgroundSprite

public void setBackgroundSprite(boolean v)
Sets if the action sprite a part of the background.

Overrides:
setBackgroundSprite in class Sprite
Parameters:
v - true if this sprite is a part of the background, false otherwise.

setParent

protected void setParent(PlayField parent)
Sets the parent playfield of the action sprite.

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

getParent

public PlayField getParent()
Gets the parent playfield of the action sprite.

Overrides:
getParent in class Sprite
Returns:
Parent playfield of this sprite.

getImage

public Image getImage()
Gets the image of the action sprite.

Overrides:
getImage in class Sprite
Returns:
Image of the sprite.

setImage

public void setImage(Image img)
Sets the image for the action sprite.

Overrides:
setImage in class Sprite
Parameters:
img - Image to set.

getBackground

public int getBackground()
Gets the background color of the action sprite.

Overrides:
getBackground in class Sprite
Returns:
The background color of the sprite.

setBackground

public void setBackground(int color)
Sets the background color for the action sprite.

Overrides:
setBackground in class Sprite
Parameters:
color - Color to set.

isVisible

public boolean isVisible()
Is the action sprite visible?

Overrides:
isVisible in class Sprite
Returns:
true if the sprite is visible, false otherwise.

setVisible

public void setVisible(boolean v)
Sets if the action sprite is visible.

Overrides:
setVisible in class Sprite
Parameters:
v - true if the sprite is visible, false otherwise.

preCollisionWith

protected boolean preCollisionWith(Sprite s)
Propagations of the pre-collision event to the action event.

Overrides:
preCollisionWith in class Sprite
Parameters:
s - Sprite with which the collision is
Returns:
true to accept the new position and the size of the sprite, false otherwise.
See Also:
Sprite.preCollisionWith(Sprite)

collisionWith

protected void collisionWith(Sprite s)
Propagations of the collision event to the action event.

Overrides:
collisionWith in class Sprite
Parameters:
s - Sprite with which the collision is
See Also:
Sprite.collisionWith(Sprite)

repaint

public void repaint()
Repaints the action component.

Overrides:
repaint in class Sprite
See Also:
Sprite.repaint()

paint

public void paint(Graphics g)
Paints the action sprite.

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

tick

public void tick(int ticks)
Propagations of the tick event to the action event if it is an instance of Tickable.

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

Genuts ME API

Genuts ME API