# Two.Sprite
Extends: Two.Rectangle
A convenient package to display still or animated images through a tiled image source. For more information on the principals of animated imagery through tiling see Texture Atlas (opens new window) on Wikipedia.
# Constructor
Argument | Description |
---|---|
path | The URL path or Two.Texture to be used as the bitmap data displayed on the sprite. |
ox | The initial x position of the Two.Sprite. |
oy | The initial y position of the Two.Sprite. |
cols | The number of columns the sprite contains. |
rows | The number of rows the sprite contains. |
frameRate | The frame rate at which the partitions of the image should playback at. |
# fromObject
Two.Sprite.fromObject
Returns: Two.Sprite
Argument | Description |
---|---|
obj | Object notation of a Two.Sprite to create a new instance |
Create a new Two.Sprite from an object notation of a Two.Sprite.
# frameRate
Two.Sprite.frameRate
The number of frames to animate against per second. Defaults to 0
for non-animated sprites.
# copy
Two.Sprite.copy
Argument | Description |
---|---|
sprite | The reference Two.Sprite |
Copy the properties of one Two.Sprite onto another.
# play
Two.Sprite.play
Argument | Description |
---|---|
firstFrame | The index of the frame to start the animation with. |
lastFrame | The index of the frame to end the animation with. Defaults to the last item in the Two.Sprite.textures. |
onLastFrame | Optional callback function to be triggered after playing the last frame. This fires multiple times when the sprite is looped. |
Initiate animation playback of a Two.Sprite.
# stop
Two.Sprite.stop
Halt animation playback of a Two.Sprite and set the current frame back to the first frame.
# clone
Two.Sprite.clone
Returns: Two.Sprite
Argument | Description |
---|---|
parent | The parent group or scene to add the clone to. |
Create a new instance of Two.Sprite with the same properties of the current sprite.
# toObject
Two.Sprite.toObject
Returns: Object
Return a JSON compatible plain object that represents the path.
# dispose
Two.Sprite.dispose
Returns: Two.Sprite
Release the sprite's renderer resources and detach all events. This method stops any running animation, clears animation callbacks, disposes the texture (calling dispose() for thorough cleanup), and inherits comprehensive cleanup from the Rectangle/Path hierarchy while preserving the renderer type for potential re-attachment.