|
Genuts API | ||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--com.genuts.gameui.Sprite | +--com.genuts.gameui.SpriteWrapper
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. |
Sprite |
cloneSprite()
Creates a new sprite wrapper of the same class as this sprite. |
protected void |
collisionWith(Sprite s)
Propagations of the collision event to the action event. |
Sprite |
getActionSprite()
Returns the action sprite. |
java.awt.Color |
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. |
java.awt.Rectangle |
getBounds()
Gets the bounds of the action sprite in the form of a Rectangle object. |
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. |
java.awt.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. |
java.awt.Point |
getPosition()
Gets the position of the action sprite in the playfield. |
int |
getRightCollisionOffset()
Gets the offset on the right side for which the collision must not be considered. |
java.awt.Dimension |
getSize()
Returns the size of the action sprite. |
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(java.awt.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(java.awt.Color 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. |
boolean |
setBounds(java.awt.Rectangle r)
Moves and resizes the action sprite to conform to the new bounding rectangle r. |
void |
setId(int id)
Sets the action sprite's id. |
void |
setImage(java.awt.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 |
public SpriteWrapper()
public SpriteWrapper(Sprite sprite)
sprite
- Sprite which really acts.Method Detail |
public Sprite getFinalActionSprite()
Sprite
SpriteWrapper
. SpriteWrapper
.
getFinalActionSprite
in class Sprite
SpriteWrapper
.public Sprite getActionSprite()
getActionSprite
in class Sprite
public void setActionSprite(Sprite sprite)
null
.
sprite
- Action sprite.public void setId(int id)
setId
in class Sprite
id
- ID of this spritepublic int getId()
getId
in class Sprite
public java.awt.Dimension getSize()
getSize
in class Sprite
public boolean setSize(int w, int h)
setSize
in class Sprite
true
if the modification was done, false
otherwise.public boolean setPosition(int x, int y)
setPosition
in class Sprite
x
- X position of the sprite.y
- Y position of the sprite.
true
if the modification was done, false
otherwise.public java.awt.Point getPosition()
getPosition
in class Sprite
public java.awt.Rectangle getBounds()
getBounds
in class Sprite
public int getX()
getX
in class Sprite
public int getY()
getY
in class Sprite
public int getWidth()
getWidth
in class Sprite
public int getHeight()
getHeight
in class Sprite
public boolean setBounds(java.awt.Rectangle r)
setBounds
in class Sprite
r
- The new bounding rectangle for this sprite.
true
if the modification was done, false
otherwise.public boolean setBounds(int x, int y, int width, int height)
setBounds
in class Sprite
x
- X position of the sprite.y
- Y position of the sprite.width
- width of the sprite.height
- height of the sprite.
true
if the modification was done, false
otherwise.public boolean isSpriteAt(int x, int y)
isSpriteAt
in class Sprite
x
- X coordinate in the sprite to check.y
- Y coordinate in the sprite to check.
true
if this sprite is under
(x,y) coordinates, false
otherwise.public void setPremode(boolean state)
setPremode
in class Sprite
state
- true
to set the pre-collision mode to true
,
false
otherwise.Sprite.setPremode(boolean)
public boolean isPremode()
isPremode
in class Sprite
true
if the pre-collision mode is true
,
false
otherwise.public boolean checkCollision(Sprite sprite)
checkCollision
in class Sprite
sprite
- Sprite to check the collision with.
true
if this sprite and the other
sprite are in collision, false
otherwise.public int getRightCollisionOffset()
getRightCollisionOffset
in class Sprite
public void setRightCollisionOffset(int offset)
setRightCollisionOffset
in class Sprite
public int getLeftCollisionOffset()
getLeftCollisionOffset
in class Sprite
public void setLeftCollisionOffset(int offset)
setLeftCollisionOffset
in class Sprite
public int getTopCollisionOffset()
getTopCollisionOffset
in class Sprite
public void setTopCollisionOffset(int offset)
setTopCollisionOffset
in class Sprite
public int getBottomCollisionOffset()
getBottomCollisionOffset
in class Sprite
public void setBottomCollisionOffset(int offset)
setBottomCollisionOffset
in class Sprite
public boolean isValidate()
isValidate
in class Sprite
true
if this parent as valid
it, false
otherwise.public void validate()
validate
in class Sprite
public void invalidate()
invalidate
in class Sprite
public boolean isBackgroundSprite()
isBackgroundSprite
in class Sprite
true
if this sprite is a
part of the background, false
otherwise.public void setBackgroundSprite(boolean v)
setBackgroundSprite
in class Sprite
v
- true
if this sprite is a
part of the background, false
otherwise.protected void setParent(PlayField parent)
setParent
in class Sprite
parent
- Parent playfield of this sprite.public PlayField getParent()
getParent
in class Sprite
public java.awt.Image getImage()
getImage
in class Sprite
public void setImage(java.awt.Image img)
setImage
in class Sprite
img
- Image to set.public java.awt.Color getBackground()
getBackground
in class Sprite
public void setBackground(java.awt.Color color)
setBackground
in class Sprite
color
- Color to set.public boolean isVisible()
isVisible
in class Sprite
true
if the sprite is visible,
false
otherwise.public void setVisible(boolean v)
setVisible
in class Sprite
v
- true
if the sprite is visible,
false
otherwise.protected boolean preCollisionWith(Sprite s)
preCollisionWith
in class Sprite
s
- Sprite with which the collision is
true
to accept the new position and the size of the
sprite, false
otherwise.Sprite.preCollisionWith(Sprite)
protected void collisionWith(Sprite s)
collisionWith
in class Sprite
s
- Sprite with which the collision isSprite.collisionWith(Sprite)
public void repaint()
repaint
in class Sprite
Sprite.repaint()
public void paint(java.awt.Graphics g)
paint
in class Sprite
g
- The graphics context to use for painting.public Sprite cloneSprite()
cloneSprite
in class Sprite
public void tick(int ticks)
Tickable
.
tick
in interface Tickable
ticks
- Number of ticks from the playfield.
|
Genuts API | ||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |