Class Sprite

  • All Implemented Interfaces:
    Updatable

    public class Sprite
    extends java.lang.Object
    implements Updatable
    Static or animated two-dimensional image that can be composited into a larger scene. Multiple sprites may use the same image data, the sprite is merely an instance of the image that can be drawn by the renderer and does not modify the image itself. Sprites can be transformed (positioned, rotated, scaled) before they are displayed.

    Sprites can have multiple possible graphical states, with each state being represented by either a static image or by an animation. States are identified by name, and are based around an internal StateMachine.

    • Constructor Detail

      • Sprite

        public Sprite()
    • Method Detail

      • addState

        public void addState​(java.lang.String name,
                             Animation graphics)
        Adds a new animation state to this sprite.
        Throws:
        java.lang.IllegalArgumentException - if a state with the same name has already been registered with this sprite.
      • addState

        public void addState​(java.lang.String name,
                             Image stateGraphics)
        Shorthand that adds a new state to this sprite that consists of a single static image.
        Throws:
        java.lang.IllegalArgumentException - if a state with the same name has already been registered with this sprite.
      • update

        public void update​(float deltaTime)
        Description copied from interface: Updatable
        Updates this object for the current frame.
        Specified by:
        update in interface Updatable
        Parameters:
        deltaTime - Elapsed time since the last frame, in seconds.
      • changeState

        public void changeState​(java.lang.String stateName)
        Changes the sprite's graphics to the state with the specified name. If the sprite was already in that stae this method does nothing.
      • resetState

        public void resetState()
        Leaves the sprite in its current state, but resets the graphics for that state to play from the beginning.
      • getActiveState

        public java.lang.String getActiveState()
      • getTimeInActiveState

        public float getTimeInActiveState()
      • getPossibleStates

        public java.util.Set<java.lang.String> getPossibleStates()
      • hasState

        public boolean hasState​(java.lang.String stateName)
      • getStateGraphics

        public Animation getStateGraphics​(java.lang.String stateName)
      • getCurrentGraphics

        public Image getCurrentGraphics()
      • getCurrentWidth

        public int getCurrentWidth()
      • getCurrentHeight

        public int getCurrentHeight()
      • setPosition

        public void setPosition​(Point2D p)
      • setPosition

        public void setPosition​(float x,
                                float y)
      • getPosition

        public Point2D getPosition()
      • setTransform

        public void setTransform​(Transform transform)
      • getTransform

        public Transform getTransform()
      • copy

        public Sprite copy()
        Creates a new sprite with states and graphics based on this one, but it starts back in its initial state.