framework
Class Sprite

java.lang.Object
  extended by framework.Sprite

public class Sprite
extends Object

A Sprite object is an image or animation together with a location. Sprites can be resized, flipped and rotated, although this will have an effect on rendering speeds (rotation especially).


Field Summary
protected  double rotation
           
protected  float x
           
protected  float y
           
 
Constructor Summary
Sprite()
           
Sprite(Animation animation)
           
Sprite(Animation animation, float x, float y)
           
Sprite(float x, float y)
           
Sprite(Image image)
           
Sprite(Image image, float x, float y)
           
 
Method Summary
 void addRotation(double rotation)
           
 void draw(Graphics2D g)
           
 Animation getAnimation()
          Get the current animation, if there is one.
 float getHeight()
           
 Image getImage()
           
 Point2D.Float getPosition()
           
 double getRotation()
           
 AffineTransform getTransform()
           
 float getWidth()
           
 float getX()
           
 float getY()
           
 boolean isFlipped()
          Indicates whether this sprite has been flipped horizontally.
 void setAnimation(Animation animation)
          Set the displayed animation, replacing the current image or animation.
 void setFlipped(boolean flip)
          Sets whether this sprite should be flipped horizontally.
 void setImage(Image image)
          Set the displayed image, replacing the current image or animation.
 void setOrigin(float x, float y)
          Set the point on the image which position and rotation operations should treat as the centre.
 void setPosition(float x, float y)
           
 void setPosition(Point2D p)
           
 void setReferencePoint(float x, float y)
          Deprecated.  
 void setRotation(double rotation)
           
 void setSize(float width, float height)
           
 void setX(float x)
           
 void setY(float y)
           
 void translate(float dx, float dy)
           
 void update(int time)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

x

protected float x

y

protected float y

rotation

protected double rotation
Constructor Detail

Sprite

public Sprite()

Sprite

public Sprite(float x,
              float y)

Sprite

public Sprite(Image image)

Sprite

public Sprite(Image image,
              float x,
              float y)

Sprite

public Sprite(Animation animation)

Sprite

public Sprite(Animation animation,
              float x,
              float y)
Method Detail

update

public void update(int time)

getImage

public Image getImage()

setImage

public void setImage(Image image)
Set the displayed image, replacing the current image or animation.


getAnimation

public Animation getAnimation()
Get the current animation, if there is one.

Returns:
the current animation, or null if a static image is set.

setAnimation

public void setAnimation(Animation animation)
Set the displayed animation, replacing the current image or animation.


getWidth

public float getWidth()

getHeight

public float getHeight()

setSize

public void setSize(float width,
                    float height)

setReferencePoint

public void setReferencePoint(float x,
                              float y)
Deprecated. 

Set the point on the image which position and rotation operations should treat as the centre. Coordinates are relative to the original image, before any scaling or rotation has taken place.

This defaults to the centre of the image, which is almost always what you want.

Parameters:
x - the x coordinate on the image of the reference point
y - the y coordinate on the image of the reference point

setOrigin

public void setOrigin(float x,
                      float y)
Set the point on the image which position and rotation operations should treat as the centre. Coordinates are between 0 and 1.

This defaults to the centre of the image, which is almost always what you want.

Parameters:
x - the x coordinate on the image of the reference point
y - the y coordinate on the image of the reference point

getX

public float getX()

getY

public float getY()

setX

public void setX(float x)

setY

public void setY(float y)

getPosition

public Point2D.Float getPosition()

setPosition

public void setPosition(float x,
                        float y)

setPosition

public void setPosition(Point2D p)

translate

public void translate(float dx,
                      float dy)

getRotation

public double getRotation()

addRotation

public void addRotation(double rotation)

setRotation

public void setRotation(double rotation)

isFlipped

public boolean isFlipped()
Indicates whether this sprite has been flipped horizontally.

Returns:
true if this sprite has been flipped horizontally

setFlipped

public void setFlipped(boolean flip)
Sets whether this sprite should be flipped horizontally.

Parameters:
flip - true if this sprite should be flipped horizontally; false otherwise

getTransform

public AffineTransform getTransform()

draw

public void draw(Graphics2D g)