Package nl.colorize.multimedialib.stage
Class Sprite
java.lang.Object
nl.colorize.multimedialib.stage.Sprite
- All Implemented Interfaces:
StageNode2D
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
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddGraphics(String stateName, Animation graphics) Adds graphics to this sprite.voidaddGraphics(String stateName, Image stateGraphics) Adds graphics to this sprite.voidCalled by the renderer at the end of frame updates, while rendering the stage.voidchangeGraphics(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.intDeprecated.Deprecated.intReturns this node's global transform, which is interpreted relative to the stage.getGraphics(String stateName) Returns the bounding box currently occopied by this node, relative to the stage.Returns this node's local transform, which is interpreted relative to its parent node.booleanhasGraphics(String stateName) voidLeaves the sprite in its current state, but resets the graphics for that state to play from the beginning.toString()Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface nl.colorize.multimedialib.stage.StageNode2D
setPosition
-
Constructor Details
-
Sprite
public Sprite()Creates a sprite without default graphics. Trying to use the sprite before graphics have been added will result in an exception. -
Sprite
Creates a sprite that uses the specified animation as its default graphics. -
Sprite
Creates a sprite that uses the specified image as its default graphics.
-
-
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() -
animate
Description copied from interface:StageNode2DCalled by the renderer at the end of frame updates, while rendering the stage.animationTimercontains the elapsed time since the currently active scene was started. This allows animations to display correctly, without the need to update every single node during each frame update.- Specified by:
animatein interfaceStageNode2D
-
getStageBounds
Description copied from interface:StageNode2DReturns the bounding box currently occopied by this node, relative to the stage. This method usesStageNode2D.getGlobalTransform().- Specified by:
getStageBoundsin interfaceStageNode2D
-
copy
Creates a new sprite with states and graphics based on this one, but it starts back in its initial state. -
toString
-
getTransform
Description copied from interface:StageNode2DReturns this node's local transform, which is interpreted relative to its parent node. The local transform can be modified by application code to modify how and where the node is displayed.- Specified by:
getTransformin interfaceStageNode2D
-
getGlobalTransform
Description copied from interface:StageNode2DReturns this node's global transform, which is interpreted relative to the stage. The global transform is updated by the renderer when drawing the stage at the end of frame updates. Recalculating the global transform is relatively expensive, and is therefore only done once per frame. This means that any changes made to a node's local transform since the last frame update may not yet been reflected in the current state of its global transform.- Specified by:
getGlobalTransformin interfaceStageNode2D
-