Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## com.huguesjohnson.tiamat.graphics
Class Sprite

    java.lang.Object
      com.huguesjohnson.tiamat.graphics.Sprite

All Implemented Interfaces:
  Storable, Drawable

    public class Sprite

extends java.lang.Object
implements Drawable, Storable

class Sprite - animated sprite

Author:
  Hugues Johnson

Field Summary
`static int` | `DIRECTION_DOWN` DIRECTION constants specify the valid directions a Sprite can travel.
`static int` | `DIRECTION_LEFT` DIRECTION constants specify the valid directions a Sprite can travel.
`static int` | `DIRECTION_RIGHT` DIRECTION constants specify the valid directions a Sprite can travel.
`static int` | `DIRECTION_UP` DIRECTION constants specify the valid directions a Sprite can travel.

Constructor Summary
`Sprite(int direction, int x, int y, java.lang.String absoluteDir, java.lang.String[][] imagePaths, java.awt.Component canvas)` Creates a new instance of Sprite.

Method Summary
`void` | `draw()` Draw the entire object.
`void` | `draw(int x, int y)` Draws the entire map at location specified by (x,y).
`void` | `draw(int x1, int y1, int x2, int y2)` Draws the map within the boundaries specified by (x1,y1) and (x2,y2).
`java.awt.Component` | `getCanvas()` Returns the canvas where this Sprite is drawn.
`java.awt.image.BufferedImage` | `getCurrentImage()` Returns the current image (frame) of animation for this Sprite.
`int` | `getDirection()` Returns the direction the sprite is facing, see DIRECTION constants.
`Sprite` | `getFollower()` A follower is a reference to another Sprite that follows this Sprite.
`java.awt.image.BufferedImage` | `getImage(int direction, int step)` Returns an image (frame) of animation.
`java.lang.String[][]` | `getImagePaths()` Returns the paths to the images that comprise this Sprite.
`java.lang.String[][]` | `getImagePathsAbsolute()` Returns the absolute paths to the images that comprise this Sprite.
`boolean` | `getIsMoving()` Returns whether this sprite is currently moving.
`boolean` | `getMovable()` Returns whether this Sprite can be moved.
`int` | `getStepIndex()` Returns the step (frame) of animation is this sprite in.
`int` | `getX()` Returns the x-coordinate of this Sprite.
`int` | `getY()` Returns the y-coordinate of this Sprite.
`boolean` | `importImageData(java.lang.String[][] imagePaths)` Imports image data, returns success of the operation.
`void` | `move(int direction)` Moves the sprite in the specified direction.
`void` | `onDeserialize(Formatter formatter, java.lang.String absoluteDir)` The onDeserialize event should be fired after an object is de-serialized.
`void` | `setAbsoluteDir(java.lang.String absoluteDir)` Sets the absolute path to the directory where images are stored.
`void` | `setCanvas(java.awt.Component canvas)` Sets the canvas where this Sprite is drawn.
`void` | `setDirection(int direction)` Sets the direction the sprite is facing, see DIRECTION constants.
`void` | `setFollower(Sprite sprite)` A follower is a reference to another Sprite that follows this Sprite.
`void` | `setImage(int direction, int step, java.lang.String imagePath)` Sets an image (frame) of animation.
`void` | `setIsMoving(boolean isMoving)` Sets whether this sprite is currently moving.
`void` | `setMovable(boolean movable)` Sets whether this Sprite can be moved.
`void` | `setStepIndex(int stepIndex)` Sets the step (frame) of animation is this sprite in.
`void` | `setX(int x)` Sets the x-coordinate of this Sprite.
`void` | `setY(int y)` Sets the y-coordinate of this Sprite.
`java.lang.String` | `toString()` Returns a string representation of the object.

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

Field Detail

### DIRECTION_UP

    public static final int DIRECTION_UP

  DIRECTION constants specify the valid directions a Sprite can travel. Constant for the up direction.

  See Also:
    Constant Field Values

### DIRECTION_DOWN

    public static final int DIRECTION_DOWN

  DIRECTION constants specify the valid directions a Sprite can travel. Constant for the down direction.

  See Also:
    Constant Field Values

### DIRECTION_LEFT

    public static final int DIRECTION_LEFT

  DIRECTION constants specify the valid directions a Sprite can travel. Constant for the left direction.

  See Also:
    Constant Field Values

### DIRECTION_RIGHT

    public static final int DIRECTION_RIGHT

  DIRECTION constants specify the valid directions a Sprite can travel. Constant for the right direction.

  See Also:
    Constant Field Values

Constructor Detail

### Sprite

    public Sprite(int direction,
                  int x,
                  int y,
                  java.lang.String absoluteDir,
                  java.lang.String[][] imagePaths,
                  java.awt.Component canvas)

  Creates a new instance of Sprite.

  Parameters:
    `direction` - The new direction the sprite is facing.
    `x` - The new x-coordinate of this Sprite.
    `y` - The new y-coordinate of this Sprite.
    `absoluteDir` - The absolute path to the directory where images are stored.
    `imagePaths` - The paths to the images that comprise this Sprite. Relative to baseImagePath.
    `canvas` - The canvas where this Sprite is drawn.

Method Detail

### getDirection

    public int getDirection()

  Returns the direction the sprite is facing, see DIRECTION constants.

  Returns:
    The direction the sprite is facing.

### setDirection

    public void setDirection(int direction)

  Sets the direction the sprite is facing, see DIRECTION constants.

  Parameters:
    `direction` - The new direction the sprite is facing.

### getStepIndex

    public int getStepIndex()

  Returns the step (frame) of animation is this sprite in.

  Returns:
    The step (frame) of animation is this sprite in.

### setStepIndex

    public void setStepIndex(int stepIndex)

  Sets the step (frame) of animation is this sprite in.

  Parameters:
    `stepIndex` - The new step (frame) of animation is this sprite in.

### getX

    public int getX()

  Returns the x-coordinate of this Sprite.

  Returns:
    The x-coordinate of this Sprite.

### setX

    public void setX(int x)

  Sets the x-coordinate of this Sprite.

  Parameters:
    `x` - The new x-coordinate of this Sprite.

### getY

    public int getY()

  Returns the y-coordinate of this Sprite.

  Returns:
    The y-coordinate of this Sprite.

### setY

    public void setY(int y)

  Sets the y-coordinate of this Sprite.

  Parameters:
    `y` - The new y-coordinate of this Sprite.

### getMovable

    public boolean getMovable()

  Returns whether this Sprite can be moved.

  Returns:
    True if this Spire can be moved.

### setMovable

    public void setMovable(boolean movable)

  Sets whether this Sprite can be moved.

  Parameters:
    `movable` - Whether this Sprite can be moved.

### getImagePaths

    public java.lang.String[][] getImagePaths()

  Returns the paths to the images that comprise this Sprite. Relative to baseImagePath.

  Returns:
    The paths to the images that comprise this Sprite. Relative to baseImagePath.

### getImagePathsAbsolute

    public java.lang.String[][] getImagePathsAbsolute()

  Returns the absolute paths to the images that comprise this Sprite.

  Returns:
    The absolute paths to the images that comprise this Sprite.

### getCurrentImage

    public java.awt.image.BufferedImage getCurrentImage()

  Returns the current image (frame) of animation for this Sprite.

  Returns:
    The current image (frame) of animation for this Sprite.

### getImage

    public java.awt.image.BufferedImage getImage(int direction,
                                                 int step)

  Returns an image (frame) of animation.

  Parameters:
    `direction` - The direction of the image.
    `step` - The step index of the image.
  Returns:
    The image at [direction]x[step].

### setImage

    public void setImage(int direction,
                         int step,
                         java.lang.String imagePath)

  Sets an image (frame) of animation.

  Parameters:
    `direction` - The direction of the image.
    `step` - The step index of the image.
    `imagePath` - The path to the image file, relative to baseImagePath.

### setAbsoluteDir

    public void setAbsoluteDir(java.lang.String absoluteDir)

  Sets the absolute path to the directory where images are stored.

  Parameters:
    `absoluteDir` - The absolute path to the directory where images are stored.

### getFollower

    public Sprite getFollower()

  A follower is a reference to another Sprite that follows this Sprite.

  Returns:
    The follower of this Sprite.

### setFollower

    public void setFollower(Sprite sprite)

  A follower is a reference to another Sprite that follows this Sprite.

  Parameters:
    `sprite` - The new follower to this Sprite.

### getCanvas

    public java.awt.Component getCanvas()

  Returns the canvas where this Sprite is drawn.

  Returns:
    The canvas where this Sprite is drawn.

### setCanvas

    public void setCanvas(java.awt.Component canvas)

  Sets the canvas where this Sprite is drawn.

  Parameters:
    `canvas` - The canvas where this Sprite is drawn.

### setIsMoving

    public void setIsMoving(boolean isMoving)

  Sets whether this sprite is currently moving.

  Parameters:
    `isMoving` - Whether this sprite is currently moving.

### getIsMoving

    public boolean getIsMoving()

  Returns whether this sprite is currently moving.

  Returns:
    Whether this sprite is currently moving.

### importImageData

    public boolean importImageData(java.lang.String[][] imagePaths)

  Imports image data, returns success of the operation.

  Parameters:
    `imagePaths` - The paths to the images that comprise this Sprite. Relative to baseImagePath.
  Returns:
    The success of the import operation.

### move

    public void move(int direction)

  Moves the sprite in the specified direction.

  Parameters:
    `direction` - The direction to move the Sprite.

### draw

    public void draw()

  Description copied from interface: `Drawable`
  Draw the entire object.

  Specified by:
    `draw` in interface `Drawable`

### draw

    public void draw(int x,
                     int y)

  Description copied from interface: `Drawable`
  Draws the entire map at location specified by (x,y).

  Specified by:
    `draw` in interface `Drawable`
  Parameters:
    `x` - The x co-ordinate.
    `y` - The y co-ordinate.

### draw

    public void draw(int x1,
                     int y1,
                     int x2,
                     int y2)

  Description copied from interface: `Drawable`
  Draws the map within the boundaries specified by (x1,y1) and (x2,y2).

  Specified by:
    `draw` in interface `Drawable`
  Parameters:
    `x1` - The x co-ordinate to start at.
    `y1` - The y co-ordinate to start at.
    `x2` - The x co-ordinate to end at.
    `y2` - The y co-ordinate to end at.

### toString

    public java.lang.String toString()

  Returns a string representation of the object.

  Overrides:
    `toString` in class `java.lang.Object`
  Returns:
    A string representation of the object.

### onDeserialize

    public void onDeserialize(Formatter formatter,
                              java.lang.String absoluteDir)

  The onDeserialize event should be fired after an object is de-serialized. This allows objects to load transient members, set their working directory, and load Storable members if needed.

  Specified by:
    `onDeserialize` in interface `Storable`
  Parameters:
    `formatter` - the formatter to use to load any storable members
    `absoluteDir` - the working directory since all paths stored in the object should be relative

Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD