|
GTGE API | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.golden.gamedev.object.Sprite
com.golden.gamedev.object.AnimatedSprite
com.golden.gamedev.object.sprite.AdvanceSprite
public class AdvanceSprite
AdvanceSprite
class is animated sprite that has status and
direction attributes, that way the animation is fully controlled by its
status and direction.
This class can be used directly, however this class meant to be subclassed.
The method that control the sprite animation and the one that need to be
override is animationChanged(int oldStat, int oldDir, int status, int direction)
.
The animationChanged
is the method that taking care the sprite
animation, everytime sprite status
or
direction
is being changed, the
animationChanged
is called automatically, and this sprite need
to adjust its animation based on the new status and direction.
setStatus(int)
,
setDirection(int)
,
animationChanged(int, int, int, int)
,
Serialized FormField Summary |
---|
Fields inherited from class com.golden.gamedev.object.Sprite |
---|
height, width |
Constructor Summary | |
---|---|
AdvanceSprite()
Creates new AdvanceSprite with null image and located at (0, 0). |
|
AdvanceSprite(BufferedImage[] image)
Creates new AdvanceSprite with specified images
and located at (0, 0). |
|
AdvanceSprite(BufferedImage[] image,
double x,
double y)
Creates new AdvanceSprite with specified images and location. |
|
AdvanceSprite(double x,
double y)
Creates new AdvanceSprite with specified location. |
Method Summary | |
---|---|
protected void |
animationChanged(int oldStat,
int oldDir,
int status,
int direction)
The sprite status and/or direction is changed, set appropriate sprite animation. |
int[] |
getAnimationFrame()
Returns sprite animation frame or null if the sprite use standard animation frame. |
int |
getDirection()
Returns current sprite direction. |
int |
getStatus()
Returns current sprite status. |
void |
render(Graphics2D g,
int xs,
int ys)
Renders sprite image to specified graphics context and specified location. |
void |
setAnimation(int stat,
int dir)
Sets sprite animation to specified status and direction. |
void |
setAnimationFrame(int[] animation)
Sets sprite animation frame to specified animation array. |
void |
setDirection(int dir)
Sets new sprite direction. |
void |
setStatus(int stat)
Sets new sprite status. |
Methods inherited from class com.golden.gamedev.object.AnimatedSprite |
---|
getAnimationTimer, getFinishAnimationFrame, getFrame, getImage, getImage, getImages, getStartAnimationFrame, isAnimate, isLoopAnim, setAnimate, setAnimationFrame, setAnimationTimer, setFrame, setImage, setImages, setLoopAnim, update, updateAnimation |
Methods inherited from class com.golden.gamedev.object.Sprite |
---|
addHorizontalSpeed, addVerticalSpeed, forceX, forceY, getBackground, getDataID, getDistance, getHeight, getHorizontalSpeed, getID, getLayer, getOldX, getOldY, getScreenX, getScreenY, getVerticalSpeed, getWidth, getX, getY, isActive, isImmutable, isOnScreen, isOnScreen, move, moveTo, moveX, moveY, render, setActive, setBackground, setDataID, setHorizontalSpeed, setID, setImmutable, setLayer, setLocation, setMovement, setSpeed, setVerticalSpeed, setX, setY, updateMovement |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public AdvanceSprite(BufferedImage[] image, double x, double y)
AdvanceSprite
with specified images and location.
image
- sprite imagesx
- sprite x-coordinatey
- sprite y-coordinatepublic AdvanceSprite(BufferedImage[] image)
AdvanceSprite
with specified images
and located at (0, 0).
Sprite.setLocation(double, double)
public AdvanceSprite(double x, double y)
AdvanceSprite
with specified location.
x
- sprite x-coordinatey
- sprite y-coordinatepublic AdvanceSprite()
AdvanceSprite
with null image and located at (0, 0). The sprite images must be set before rendering.
AnimatedSprite.setImages(BufferedImage[])
,
Sprite.setLocation(double, double)
Method Detail |
---|
public void setAnimationFrame(int[] animation)
Use this if only the animation is not following the standard image frames, for example if the sprite walking the animation is 2-3-4-2-1, then set the animation frame to : setAnimationFrame(new int[] { 2, 3, 4, 2, 1 });
AnimatedSprite.setAnimationFrame(int, int)
public int[] getAnimationFrame()
protected void animationChanged(int oldStat, int oldDir, int status, int direction)
This method is responsible to set the sprite animation. By default this method do nothing.
AnimatedSprite.setAnimationFrame(int, int)
,
setAnimationFrame(int[])
,
AnimatedSprite.setImages(BufferedImage[])
,
AnimatedSprite.setAnimate(boolean)
,
AnimatedSprite.setLoopAnim(boolean)
public void setDirection(int dir)
If the sprite direction is changed (current direction != new direction),
animationChanged(int, int, int, int)
will be notified.
animationChanged(int, int, int, int)
,
setStatus(int)
public int getDirection()
public void setStatus(int stat)
If the sprite status is changed (current status != new status),
animationChanged(int, int, int, int)
will be notified.
animationChanged(int, int, int, int)
,
setDirection(int)
public int getStatus()
public void setAnimation(int stat, int dir)
stat
- the new sprite statusdir
- the new sprite directionanimationChanged(int, int, int, int)
public void render(Graphics2D g, int xs, int ys)
Sprite
render
in class AnimatedSprite
g
- graphics contextxs
- screen x-coordinateys
- screen y-coordinate
|
GTGE API | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |