Two.Sprite

Extends: Two.Rectangle

A convenient package to display still or animated images through a tiled image source. For more information on the principles of animated imagery through tiling see Texture Atlas on Wikipedia.

Constructor

ArgumentDescription
srcThe URL path or Two.Texture to be used as the bitmap data displayed on the sprite.
oxThe initial x position of the Two.Sprite.
oyThe initial y position of the Two.Sprite.
colsThe number of columns the sprite contains.
rowsThe number of rows the sprite contains.
frameRateThe frame rate at which the partitions of the image should playback at.

Properties

A list of properties that are on every Two.Sprite.

fromObject

Returns: Two.Sprite

ArgumentDescription
objObject notation of a Two.Sprite to create a new instance

Create a new Two.Sprite from an object notation of a Two.Sprite.

nota-bene

Works in conjunction with Two.Sprite.toObject

texture

The texture to be used as bitmap data to display image in the scene.

columns

The number of columns to split the texture into. Defaults to 1.

rows

The number of rows to split the texture into. Defaults to 1.

frameRate

The number of frames to animate against per second. Defaults to 0 for non-animated sprites.

index

The index of the current tile of the sprite to display. Defaults to 0.

copy

ArgumentDescription
spriteThe reference Two.Sprite

Copy the properties of one Two.Sprite onto another.

play

ArgumentDescription
firstFrameThe index of the frame to start the animation with.
lastFrameThe index of the frame to end the animation with. Defaults to the last item in the Two.Sprite.textures.
onLastFrameOptional 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

Halt animation playback of a Two.Sprite and set the current frame back to the first frame.

clone

Returns: Two.Sprite

ArgumentDescription
parentThe 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

Returns: Object

Return a JSON compatible plain object that represents the path.

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.