Class Sprite

java.lang.Object
nl.colorize.multimedialib.stage.Sprite
All Implemented Interfaces:
Updatable, Graphic2D

public class Sprite extends Object implements Graphic2D
Static or animated image that can be displayed on the stage. Multiple sprites can use the same image data. As sprites represent an instance of the original image, sprites can be transformed without affecting or modifying the underlying image data.

Sprites support multiple graphical states, where each state can be identified by its name. The currently active graphics are updated automatically for as long as the sprite is on the stage.

  • Constructor Details

    • Sprite

      public Sprite()
    • Sprite

      public Sprite(Animation anim)
    • Sprite

      public Sprite(Image image)
  • Method Details

    • addGraphics

      public void addGraphics(String stateName, Animation graphics)
      Adds graphics to this sprite. If the sprite does not contain graphics yet, this will automatically change the sprite's current graphics. Otherwise, changing the sprite's graphics can be done later using the specified name.
      Throws:
      IllegalArgumentException - if a state with the same name has already been registered with this sprite.
    • addGraphics

      public void addGraphics(String stateName, Image stateGraphics)
      Adds graphics to this sprite. If the sprite does not contain graphics yet, this will automatically change the sprite's current graphics. Otherwise, changing the sprite's graphics can be done later using the specified name.
      Throws:
      IllegalArgumentException - if a state with the same name has already been registered with this sprite.
    • changeGraphics

      public void changeGraphics(String stateName)
      Changes this sprite's graphics to the state identified by the specified name. If the sprite is already in that state, this method does nothing.
      Throws:
      IllegalArgumentException - if the sprite does not define any graphics for the requested state.
    • resetCurrentGraphics

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

      public String getActiveState()
    • getPossibleStates

      public Set<String> getPossibleStates()
    • hasGraphics

      public boolean hasGraphics(String stateName)
    • getGraphics

      public Animation getGraphics(String stateName)
    • getCurrentStateGraphics

      @Deprecated public Animation getCurrentStateGraphics()
      Deprecated.
    • getCurrentStateTimer

      @Deprecated public Timer getCurrentStateTimer()
      Deprecated.
    • getCurrentGraphics

      public Image getCurrentGraphics()
    • getCurrentWidth

      public int getCurrentWidth()
    • getCurrentHeight

      public int getCurrentHeight()
    • update

      public void update(float deltaTime)
      Description copied from interface: Updatable
      Updates this object for the current frame. deltaTime indicates the elapsed time since the last frame update, in seconds.
      Specified by:
      update in interface Updatable
    • getStageBounds

      public Rect getStageBounds()
      Description copied from interface: Graphic2D
      Returns the smallest possible rectangle that can contain this graphic, based on its current position and size. The returned coordinates are relative to the stage, not relative to the graphic's parent.
      Specified by:
      getStageBounds in interface Graphic2D
    • copy

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

      public String toString()
      Overrides:
      toString in class Object
    • getLocation

      public DisplayListLocation getLocation()
      Description copied from interface: Graphic2D
      Returns the DisplayListLocation attached to this graphic, which is used by the renderer to determine how this graphic should be drawn.
      Specified by:
      getLocation in interface Graphic2D