Class Sprite
- java.lang.Object
-
- nl.colorize.multimedialib.graphics.Sprite
-
- All Implemented Interfaces:
Updatable
public class Sprite extends java.lang.Object implements Updatable
Static or animated two-dimensional image that can be integrated 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 (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.
-
-
Constructor Summary
Constructors Constructor Description Sprite()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddState(java.lang.String name, Animation graphics)Adds a new animation state to this sprite.voidaddState(java.lang.String name, Image stateGraphics)Shorthand that adds a new state to this sprite that consists of a single static image.voidchangeState(java.lang.String stateName)Changes the sprite's graphics to the state with the specified name.Spritecopy()Creates a new sprite with states and graphics based on this one, but it starts back in its initial state.java.util.Set<java.lang.String>getAvailableStates()ImagegetCurrentGraphics()intgetCurrentHeight()java.lang.StringgetCurrentState()intgetCurrentWidth()AnimationgetStateGraphics(java.lang.String stateName)floatgetTimeInCurrentState()booleanhasState(java.lang.String stateName)voidresetState()Leaves the sprite in its current state, but resets the graphics for that state to play from the beginning.voidupdate(float deltaTime)Updates this object for the current frame.
-
-
-
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:UpdatableUpdates this object for the current frame.
-
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.
-
getCurrentState
public java.lang.String getCurrentState()
-
getTimeInCurrentState
public float getTimeInCurrentState()
-
getAvailableStates
public java.util.Set<java.lang.String> getAvailableStates()
-
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()
-
copy
public Sprite copy()
Creates a new sprite with states and graphics based on this one, but it starts back in its initial state.
-
-