|
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
public class AnimatedSprite
AnimatedSprite
class is sprite that use several images and can
be animated.
To animate animated sprite, simply use
setAnimate(true), and to loop the animation
use setLoopAnim(true).
To control animation speed, adjust the sprite
animation timer delay.
To control animation frame sequence, use
setAnimationFrame(int startframe, int endframe)
.
Animated sprite usage example :
AnimatedSprite sprite; BufferedImage[] spriteImage; // create the sprite sprite = new AnimatedSprite(spriteImage, 0, 0); // set animation speed 100 milliseconds for each frame sprite.getAnimationTimer().setDelay(100); // set animation frame starting from the first image to the third image sprite.setAnimationFrame(0, 2); // animate the sprite, and perform continous animation sprite.setAnimate(true); sprite.setLoopAnim(true);
AnimatedSprite
is only to make a simple animated sprite, there
is no property to control sprite animation behaviour. For more control
to determine sprite animation based on sprite status and direction, use
AdvanceSprite
.
AdvanceSprite
,
Serialized FormField Summary |
---|
Fields inherited from class com.golden.gamedev.object.Sprite |
---|
height, width |
Constructor Summary | |
---|---|
AnimatedSprite()
Creates new AnimatedSprite with null image and located at (0, 0). |
|
AnimatedSprite(BufferedImage[] image)
Creates new AnimatedSprite with specified images
and located at (0, 0). |
|
AnimatedSprite(BufferedImage[] image,
double x,
double y)
Creates new AnimatedSprite with specified images and location. |
|
AnimatedSprite(double x,
double y)
Creates new AnimatedSprite with null image to specified location. |
Method Summary | |
---|---|
Timer |
getAnimationTimer()
Returns sprite animation timer. |
int |
getFinishAnimationFrame()
Returns the finish animation frame of this sprite. |
int |
getFrame()
Returns current frame animation. |
BufferedImage |
getImage()
Returns image of current frame. |
BufferedImage |
getImage(int i)
Returns image of specified frame. |
BufferedImage[] |
getImages()
Returns sprite animation images. |
int |
getStartAnimationFrame()
Returns the start animation frame of this frame. |
boolean |
isAnimate()
Returns whether this sprite is currently animating or not. |
boolean |
isLoopAnim()
Returns whether this sprite animation is looping continously or not. |
void |
render(Graphics2D g,
int xs,
int ys)
Renders sprite image to specified graphics context and specified location. |
void |
setAnimate(boolean b)
Sets true to animate this sprite. |
void |
setAnimationFrame(int start,
int finish)
Sets sprite animation sequence, starting from start frame
and ended at finish frame. |
void |
setAnimationTimer(Timer t)
Sets sprite animation timer. |
void |
setFrame(int i)
Sets current frame animation. |
void |
setImage(BufferedImage image)
This method is obsolete on animated sprite, since animated sprite always use several images for its animation. |
void |
setImages(BufferedImage[] image)
Sets sprite animation images. |
void |
setLoopAnim(boolean b)
Sets true to animate this sprite continously. |
void |
update(long elapsedTime)
Updates this sprite. |
protected void |
updateAnimation()
Updates sprite animation. |
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 AnimatedSprite(BufferedImage[] image, double x, double y)
AnimatedSprite
with specified images and location.
image
- sprite imagesx
- sprite x-coordinatey
- sprite y-coordinatepublic AnimatedSprite(BufferedImage[] image)
AnimatedSprite
with specified images
and located at (0, 0).
Sprite.setLocation(double, double)
public AnimatedSprite(double x, double y)
AnimatedSprite
with null image to specified location. The sprite images must be set before rendering.
x
- sprite x-coordinatey
- sprite y-coordinatepublic AnimatedSprite()
AnimatedSprite
with null image and located at (0, 0). The sprite images must be set before rendering.
setImages(BufferedImage[])
,
Sprite.setLocation(double, double)
Method Detail |
---|
public void setImages(BufferedImage[] image)
public void setImage(BufferedImage image)
setImage
in class Sprite
setImages(BufferedImage[])
public BufferedImage[] getImages()
public BufferedImage getImage(int i)
public BufferedImage getImage()
getImage
in class Sprite
public void setFrame(int i)
public int getFrame()
public void setAnimationFrame(int start, int finish)
start
frame
and ended at finish
frame. The sprite current frame is
automatically set to start
frame.
The first images is frame 0
and the last images is
frame getImages().length-1
.
For example to make the sprite animated from the first image to the third image :
AnimatedSprite sprite; // animate from first image to third image sprite.setAnimationFrame(0, 2); sprite.setAnimate(true);Note: If the
start
and finish
frame is same
with current animation frame, no action is taken.
public int getStartAnimationFrame()
setAnimationFrame(int, int)
public int getFinishAnimationFrame()
setAnimationFrame(int, int)
public void update(long elapsedTime)
Sprite
update
in class Sprite
protected void updateAnimation()
The animation frame is increased by one, and if the animation frame is exceeded total animation frame, the animation frame is back to the first animation frame, and stop the animation if the animation is not set to loop continously.
public void render(Graphics2D g, int xs, int ys)
Sprite
render
in class Sprite
g
- graphics contextxs
- screen x-coordinateys
- screen y-coordinatepublic boolean isAnimate()
public void setAnimate(boolean b)
public boolean isLoopAnim()
public void setLoopAnim(boolean b)
public void setAnimationTimer(Timer t)
public Timer getAnimationTimer()
|
GTGE API | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |