|
Genuts ME API | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.genuts.gameui.Sprite
A sprite is an object having a graphical representation that have its own behavior.
Class Sprite can be extended directly to specify completly the behavior.
To know if a sprite is in collision with another one, the method checkCollision(Sprite)
is called by the playfield for each sprite which is not a background sprite.
After that, when the collision event is fired, the method collisionWith(Sprite)
is called to perform the action for the collision.
A sprite can be identified by its ID, to avoid specialization of a sprite to identify it.
For special behavior, user interaction and other modifications, please to use a SpriteWrapper
.
In that way, a sprite on which a sprite wrapper interacts is called an action sprite.
setId(int)
,
getId()
Constructor Summary | |
Sprite()
Initialize a simple sprite. |
|
Sprite(Image image)
Initializes the sprite with an image. |
|
Sprite(int w,
int h)
Initializes the sprite with a size. |
Method Summary | |
boolean |
checkCollision(Sprite sprite)
Checks collision of this sprite with another sprite or with the edges of the playfield. |
protected void |
collisionWith(Sprite s)
Receives the event that this sprite is collision with another sprite. |
Sprite |
getActionSprite()
Returns the action sprite. |
int |
getBackground()
Gets the background color of this 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 . |
Sprite |
getFinalWrapper()
Gets the final wrapper sprite of this sprite. |
int |
getHeight()
Gets the height of the sprite. |
int |
getId()
Gets the id of this sprite. |
Image |
getImage()
Gets the image of this 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 this 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 sprite. |
Sprite |
getWrapper()
Gets the wrapper sprite of this sprite. |
int |
getX()
Gets the X coordinate of the sprite. |
int |
getY()
Gets the Y coordinate of the sprite. |
void |
invalidate()
Invalidates this sprite. |
boolean |
isBackgroundSprite()
Is this sprite a piece of the background? |
boolean |
isPremode()
Returns the pre-collision mode state for this sprite. |
boolean |
isSpriteAt(int x,
int y)
Indicates if this sprite is under (x,y) coordinates. |
boolean |
isValidate()
Indicates if this sprite as been valideted by its parent. |
boolean |
isVisible()
Indicates if the sprite is visible. |
void |
paint(Graphics g)
Draws the sprite. |
protected boolean |
preCollisionWith(Sprite s)
Receives the event that this sprite is in pre-collision with another sprite. |
void |
repaint()
Repaints this component. |
void |
setBackground(int color)
Sets the background color for this sprite. |
void |
setBackgroundSprite(boolean v)
Sets if this sprite is a piece 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 sprite to conform to the new bounding rectangle. |
void |
setId(int id)
Sets this sprite's id. |
void |
setImage(Image img)
Sets the image for this 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 this sprite. |
boolean |
setPosition(int x,
int y)
Sets the position of this sprite in the playfield. |
void |
setPremode(boolean state)
Sets the pre-collision mode for this 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 this 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 sprite is visible. |
protected void |
setWrapper(SpriteWrapper wrapper)
Sets the wrapper sprite of this sprite. |
java.lang.String |
toString()
Returns a string representation of this Sprite. |
void |
validate()
Validates this sprite by its parent. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
public Sprite()
public Sprite(int w, int h)
w
- Width of the sprite.h
- Height of the sprite.public Sprite(Image image)
image
- Image to display for the sprite.Method Detail |
public Sprite getWrapper()
public Sprite getFinalWrapper()
protected void setWrapper(SpriteWrapper wrapper)
wrapper
- Wrapper sprite of this sprite.public Sprite getFinalActionSprite()
SpriteWrapper
. SpriteWrapper
.
SpriteWrapper
.public Sprite getActionSprite()
public void setId(int id)
id
- ID of this spritepublic int getId()
public boolean setSize(int w, int h)
true
if the modification was done, false
otherwise.public boolean setPosition(int x, int y)
x
- X position of the sprite.y
- Y position of the sprite.
true
if the modification was done, false
otherwise.public int getX()
public int getY()
public int getWidth()
public int getHeight()
public boolean setBounds(int x, int y, int width, int height)
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)
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)
The pre-collision mode allows to a sprite to detect a collision just before it happens.
When the size, or the position or bounds of this sprite changes,
and if the pre-collision mode is set to true
, a check for collision is
made and if it happens, it call launch a preCollisionWith(Sprite) event.
This event has to return true
if the new setting is correct,
false
otherwise.
state
- true
to set the pre-collision mode to true
,
false
otherwise.public boolean isPremode()
true
if the pre-collision mode is true
,
false
otherwise.public boolean checkCollision(Sprite sprite)
sprite
- Sprite to check the collision with.
true
if this sprite and the other
sprite are in collision, false
otherwise.public int getRightCollisionOffset()
public void setRightCollisionOffset(int offset)
public int getLeftCollisionOffset()
public void setLeftCollisionOffset(int offset)
public int getTopCollisionOffset()
public void setTopCollisionOffset(int offset)
public int getBottomCollisionOffset()
public void setBottomCollisionOffset(int offset)
public boolean isValidate()
true
if this parent as valid
it, false
otherwise.public void validate()
public void invalidate()
public boolean isBackgroundSprite()
true
if this sprite is a
piece of the background, false
otherwise.public void setBackgroundSprite(boolean v)
v
- true
if this sprite is a
piece of the background, false
otherwise.protected void setParent(PlayField parent)
parent
- Parent playfield of this sprite.public PlayField getParent()
public Image getImage()
public void setImage(Image img)
img
- Image to set.public int getBackground()
public void setBackground(int color)
color
- Color to set.public boolean isVisible()
true
if the sprite is visible,
false
otherwise.public void setVisible(boolean v)
v
- true
if the sprite is visible,
false
otherwise.protected boolean preCollisionWith(Sprite s)
true
.
Coordonates and size of this sprite are temporally set,
it is in charge of the developper to validate them by returning
true
, or to refuse them by returning false
.
By default, it returns true
.
s
- Sprite with which the pre-collision is, null
if it is with the edge of the playfield.
true
to accept the new position and the size of the
sprite, false
otherwise.protected void collisionWith(Sprite s)
s
- Sprite with which the collision is, null
if it is with the edge of the playfield.public void repaint()
This method causes a call to this component's paint method as soon as possible.
paint(Graphics)
public void paint(Graphics g)
g
- The graphics context to use for painting.public java.lang.String toString()
|
Genuts ME API | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |