GTGE API

com.golden.gamedev.object.sprite
Class AdvanceSprite

java.lang.Object
  extended by com.golden.gamedev.object.Sprite
      extended by com.golden.gamedev.object.AnimatedSprite
          extended by com.golden.gamedev.object.sprite.AdvanceSprite
All Implemented Interfaces:
Serializable
Direct Known Subclasses:
VolatileSprite

public class AdvanceSprite
extends AnimatedSprite

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.

See Also:
setStatus(int), setDirection(int), animationChanged(int, int, int, int), Serialized Form

Field 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

AdvanceSprite

public AdvanceSprite(BufferedImage[] image,
                     double x,
                     double y)
Creates new AdvanceSprite with specified images and location.

Parameters:
image - sprite images
x - sprite x-coordinate
y - sprite y-coordinate

AdvanceSprite

public AdvanceSprite(BufferedImage[] image)
Creates new AdvanceSprite with specified images and located at (0, 0).

See Also:
Sprite.setLocation(double, double)

AdvanceSprite

public AdvanceSprite(double x,
                     double y)
Creates new AdvanceSprite with specified location.

Parameters:
x - sprite x-coordinate
y - sprite y-coordinate

AdvanceSprite

public AdvanceSprite()
Creates new AdvanceSprite with null image and located at (0, 0).

The sprite images must be set before rendering.

See Also:
AnimatedSprite.setImages(BufferedImage[]), Sprite.setLocation(double, double)
Method Detail

setAnimationFrame

public void setAnimationFrame(int[] animation)
Sets sprite animation frame to specified animation array. The sprite will be animated according to the animation array.

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 });

See Also:
AnimatedSprite.setAnimationFrame(int, int)

getAnimationFrame

public int[] getAnimationFrame()
Returns sprite animation frame or null if the sprite use standard animation frame.


animationChanged

protected void animationChanged(int oldStat,
                                int oldDir,
                                int status,
                                int direction)
The sprite status and/or direction is changed, set appropriate sprite animation.

This method is responsible to set the sprite animation. By default this method do nothing.

See Also:
AnimatedSprite.setAnimationFrame(int, int), setAnimationFrame(int[]), AnimatedSprite.setImages(BufferedImage[]), AnimatedSprite.setAnimate(boolean), AnimatedSprite.setLoopAnim(boolean)

setDirection

public void setDirection(int dir)
Sets new sprite direction. Direction is the direction which the sprite is facing, like left, right, up, down, each direction has its own animation based on its status.

If the sprite direction is changed (current direction != new direction), animationChanged(int, int, int, int) will be notified.

See Also:
animationChanged(int, int, int, int), setStatus(int)

getDirection

public int getDirection()
Returns current sprite direction.


setStatus

public void setStatus(int stat)
Sets new sprite status. Status is the sprite status no matter in which directional the sprite is facing, like walking status, standing status, jumping status.

If the sprite status is changed (current status != new status), animationChanged(int, int, int, int) will be notified.

See Also:
animationChanged(int, int, int, int), setDirection(int)

getStatus

public int getStatus()
Returns current sprite status.


setAnimation

public void setAnimation(int stat,
                         int dir)
Sets sprite animation to specified status and direction. This method to simplify setting sprite status and direction at once.

Parameters:
stat - the new sprite status
dir - the new sprite direction
See Also:
animationChanged(int, int, int, int)

render

public void render(Graphics2D g,
                   int xs,
                   int ys)
Description copied from class: Sprite
Renders sprite image to specified graphics context and specified location.

Overrides:
render in class AnimatedSprite
Parameters:
g - graphics context
xs - screen x-coordinate
ys - screen y-coordinate

GTGE API

Copyright © 2003-2005 Golden T Studios. All rights reserved. Use is subject to license terms.
GoldenStudios.or.id