package graphicsManager; import java.awt.image.BufferedImage; /** * * @author Sam * SpriteImage holds a BufferedImage as well as the coordinates * used for drawing. May implement a movable interface. For animations * create a new class or make a generic animation algorithm. */ public class SpriteImage extends Object { //will implement a 'Movable' interface private BufferedImage sprite; private int x =0; private int y =0; //----------- Constructors ---------- // public SpriteImage(BufferedImage buffImg, int locX, int locY) { sprite = buffImg; x = locX; y = locY; } // --------- optimizations ---------- // public void flush() { sprite.flush(); } public void finalize() { flush(); sprite = null; } //---------accessors ------------- // public int getX() { return x; } public int getY() { return y; } public BufferedImage getImage() { return sprite; } public void setX(int newX) { if ( newX < 0) x = 0; else x = newX; } public void setY(int newY) { if (newY < 0) y = 0; else y = newY; } public void setLocation(int newX, int newY) { //set X if ( newX < 0) x = 0; else x = newX; //set Y if (newY < 0) y = 0; else y = newY; } //------- overloaded -------------- // inherited from object public String toString() { String tostring = "Sprite, (" + x + "," + y + ")."; return tostring; } public boolean equals(Object obj) { SpriteImage sprite = (SpriteImage)obj; if ((sprite.x == x) && (sprite.y == y)) return true; else return false; } public SpriteImage clone() { SpriteImage clone = new SpriteImage(sprite, x, y); return clone; } }