Package nl.colorize.multimedialib.stage
Class Sprite
java.lang.Object
nl.colorize.multimedialib.stage.Sprite
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 Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
addGraphics
(String stateName, Animation graphics) Adds graphics to this sprite.void
addGraphics
(String stateName, Image stateGraphics) Adds graphics to this sprite.void
changeGraphics
(String stateName) Changes this sprite's graphics to the state identified by the specified name.copy()
Creates a new sprite with states and graphics based on this one, but it starts back in its initial state.int
Deprecated.Deprecated.int
getGraphics
(String stateName) Returns theDisplayListLocation
attached to this graphic, which is used by the renderer to determine how this graphic should be drawn.Returns the smallest possible rectangle that can contain this graphic, based on its current position and size.boolean
hasGraphics
(String stateName) void
Leaves the sprite in its current state, but resets the graphics for that state to play from the beginning.toString()
void
update
(float deltaTime) Updates this object for the current frame.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface nl.colorize.multimedialib.stage.Graphic2D
getGlobalTransform, getTransform, hitTest, setPosition
-
Constructor Details
-
Sprite
public Sprite() -
Sprite
-
Sprite
-
-
Method Details
-
addGraphics
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
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
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
-
getPossibleStates
-
hasGraphics
-
getGraphics
-
getCurrentStateGraphics
Deprecated. -
getCurrentStateTimer
Deprecated. -
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. -
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 interfaceGraphic2D
-
copy
Creates a new sprite with states and graphics based on this one, but it starts back in its initial state. -
toString
-
getLocation
Description copied from interface:Graphic2D
Returns theDisplayListLocation
attached to this graphic, which is used by the renderer to determine how this graphic should be drawn.- Specified by:
getLocation
in interfaceGraphic2D
-