All Classes Functions Variables Enumerations Properties Events
Public Types | Public Member Functions | Static Public Member Functions | Public Attributes | Properties
tk2dAnimatedSprite Class Reference

Sprite implementation which plays and maintains animations. More...

Inherits tk2dSprite.

List of all members.

Public Types

enum  Anchor
 Anchor. NOTE: The order in this enum is deliberate, to initialize at LowerLeft for backwards compatibility. This is also the reason it is local here. Other Anchor enums are NOT compatbile. Do not cast. More...

Public Member Functions

delegate void AnimationCompleteDelegate (tk2dAnimatedSprite sprite, int clipId)
 Animation complete delegate.
delegate void AnimationEventDelegate (tk2dAnimatedSprite sprite, tk2dSpriteAnimationClip clip, tk2dSpriteAnimationFrame frame, int frameNum)
 Animation event delegate.
void Play ()
 Play the active clip. Will restart the clip if called again. Will restart the clip at clipStartTime if called while the clip is playing.
void Play (float clipStartTime)
 Play the active clip, starting "clipStartTime" seconds into the clip. Will restart the clip at clipStartTime if called while the clip is playing.
void PlayFromFrame (int frame)
 Play the active clip, starting at the frame specified. Will restart the clip at frame if called while the clip is playing.
void Play (string name)
 Play the specified clip. Will restart the clip at clipStartTime if called while the clip is playing.
void PlayFromFrame (string name, int frame)
 Play the specified clip, starting at the frame specified. Will restart the clip at frame if called while the clip is playing.
void Play (string name, float clipStartTime)
 Play the specified clip, starting "clipStartTime" seconds into the clip. Will restart the clip at clipStartTime if called while the clip is playing.
void Stop ()
 Stop the currently playing clip.
void StopAndResetFrame ()
 Stops the currently playing animation and reset to the first frame in the animation.
bool isPlaying ()
 Is a clip currently playing? Obselete, use tk2dSpriteAnimation.Playing instead.
bool IsPlaying (string name)
 Is the named clip currently active & playing?
bool IsPlaying (tk2dSpriteAnimationClip clip)
 Is this clip currently active & playing?
int GetClipIdByName (string name)
 Resolves an animation clip by name and returns a unique id. This is a convenient alias to tk2dSpriteAnimation.GetClipIdByName
tk2dSpriteAnimationClip GetClipByName (string name)
void Play (int id)
 Play the clip specified by identifier. Will restart the clip at clipStartTime if called while the clip is playing.
void PlayFromFrame (int id, int frame)
 Play the clip specified by identifier, starting at the specified frame. Will restart the clip at clipStartTime if called while the clip is playing.
void Play (int clipId, float clipStartTime)
 Play the clip specified by identifier. Will restart the clip at clipStartTime if called while the clip is playing.
void Play (tk2dSpriteAnimationClip clip, float clipStartTime)
 Play the clip specified by identifier. Will restart the clip at clipStartTime if called while the clip is playing.
void Play (tk2dSpriteAnimationClip clip, float clipStartTime, float overrideFps)
 Play the clip specified by identifier. Will restart the clip at clipStartTime if called while the clip is playing. No defaults to play nice with default MonoDevelop configuration.
void Pause ()
 Pause the currently playing clip. Will do nothing if the clip is currently paused.
void Resume ()
 Resume the currently paused clip. Will do nothing if the clip hasn't been paused.
void SetFrame (int currFrame)
 Sets the current frame. The animation will wrap if the selected frame exceeds the number of frames in the clip. This variant WILL trigger an event if the current frame has a trigger defined.
void SetFrame (int currFrame, bool triggerEvent)
 Sets the current frame. The animation will wrap if the selected frame exceeds the number of frames in the clip.
override void Build ()
 Rebuilds the mesh data for this sprite. Not usually necessary to call this, unless some internal states are modified.
void FlipX ()
 Flips the sprite horizontally.
void FlipY ()
 Flips the sprite vertically.
void SetSprite (int newSpriteId)
 Sets the sprite by identifier.
bool SetSprite (string spriteName)
 Sets the sprite by name. The sprite will be selected from the current collection.
void SetSprite (tk2dSpriteCollectionData newCollection, int spriteId)
 Sets sprite by identifier from the new collection.
bool SetSprite (tk2dSpriteCollectionData newCollection, string spriteName)
 Sets sprite by name from the new collection.
void SwitchCollectionAndSprite (tk2dSpriteCollectionData newCollection, int newSpriteId)
 Switches the sprite collection and sprite. Simply set the spriteId property when you don't need to switch the sprite collection. This will be deprecated in a future release, use SetSprite instead.
bool SwitchCollectionAndSprite (tk2dSpriteCollectionData newCollection, string spriteName)
 Switches the sprite collection and sprite. Simply set the spriteId property when you don't need to switch the sprite collection. This will be deprecated in a future release, use SetSprite instead.
void MakePixelPerfect ()
 Makes the sprite pixel perfect to the active camera. Automatically detects tk2dCamera if present Otherwise uses Camera.main.
int GetSpriteIdByName (string name)
 Resolves a sprite name and returns a unique id for the sprite. Convenience alias of tk2dSpriteCollectionData.GetSpriteIdByName
Bounds GetBounds ()
 Gets the local space bounds of the sprite.
Bounds GetUntrimmedBounds ()
 Gets untrimmed local space bounds of the sprite. This is the size of the sprite before 2D Toolkit trims away empty space in the sprite. Use this when you need to position sprites in a grid, etc, when the trimmed bounds is not sufficient.
tk2dSpriteDefinition GetCurrentSpriteDef ()
 Gets the current sprite definition.

Static Public Member Functions

static tk2dAnimatedSprite AddComponent (GameObject go, tk2dSpriteAnimation anim, int clipId)
 Adds a tk2dAnimatedSprite as a component to the gameObject passed in, setting up necessary parameters and building geometry.
static tk2dSprite AddComponent (GameObject go, tk2dSpriteCollectionData spriteCollection, int spriteId)
 Adds a tk2dSprite as a component to the gameObject passed in, setting up necessary parameters and building geometry. Convenience alias of tk2dBaseSprite.AddComponent<tk2dSprite>(...).
static tk2dSprite AddComponent (GameObject go, tk2dSpriteCollectionData spriteCollection, string spriteName)
 Adds a tk2dSprite as a component to the gameObject passed in, setting up necessary parameters and building geometry. Convenience alias of tk2dBaseSprite.AddComponent<tk2dSprite>(...).
static GameObject CreateFromTexture (Texture texture, tk2dRuntime.SpriteCollectionSize size, Rect region, Vector2 anchor)
 Create a sprite (and gameObject) displaying the region of the texture specified. Use tk2dSpriteCollectionData.CreateFromTexture if you need to create a sprite collection with multiple sprites. Convenience alias of tk2dBaseSprite.CreateFromTexture<tk2dSprite>(...)
static T AddComponent< T > (GameObject go, tk2dSpriteCollectionData spriteCollection, int spriteId)
 Adds a tk2dBaseSprite derived class as a component to the gameObject passed in, setting up necessary parameters and building geometry.
static T AddComponent< T > (GameObject go, tk2dSpriteCollectionData spriteCollection, string spriteName)
 Adds a tk2dBaseSprite derived class as a component to the gameObject passed in, setting up necessary parameters and building geometry. Shorthand using sprite name.
static GameObject CreateFromTexture< T > (Texture texture, tk2dRuntime.SpriteCollectionSize size, Rect region, Vector2 anchor)
 Create a sprite (and gameObject) displaying the region of the texture specified. Use tk2dSpriteCollectionData.CreateFromTexture if you need to create a sprite collection with multiple sprites.

Public Attributes

tk2dSpriteAnimation anim
 tk2dSpriteAnimation
int clipId = 0
 Currently playing/active clip.
bool playAutomatically = false
 Interface option to play the animation automatically when instantiated / game is started. Useful for background looping animations.
bool createCollider = false
 Interface option to create an animated box collider for this animated sprite.
AnimationCompleteDelegate animationCompleteDelegate
 Animation complete event. This is called when the animation has completed playing. Will not trigger on looped animations.
AnimationEventDelegate animationEventDelegate
 Animation event. This is called when the frame displayed has tk2dSpriteAnimationFrame.triggerEvent set. The triggering frame is passed to the delegate, and the eventInfo / Int / Float can be extracted from there.
bool pixelPerfect = false
 Specifies if this sprite is kept pixel perfect.
BoxCollider boxCollider = null
 Internal cached version of the box collider created for this sprite, if present.
MeshCollider meshCollider = null
 Internal cached version of the mesh collider created for this sprite, if present.

Properties

static bool g_paused [get, set]
 Globally pause all animated sprites.
bool Paused [get, set]
 Get or set pause state on this current sprite.
tk2dSpriteAnimationClip CurrentClip [get]
 The currently active or playing tk2dSpriteAnimationClip
float ClipTimeSeconds [get]
 The current clip time in seconds.
float ClipFps [get, set]
 Current frame rate of the playing clip. May have been overriden by the user. Set to 0 to default to the clips fps.
bool Playing [get]
 Is a clip currently playing? Will return true if the clip is playing, but is paused.
tk2dSpriteCollectionData Collection [get, set]
 Deprecation warning: the set accessor will be removed in a future version. Use SwitchCollectionAndSprite when you need to switch sprite collection.
Color color [get, set]
 Gets or sets the color.
Vector3 scale [get, set]
 Gets or sets the scale.
int spriteId [get, set]
 Gets or sets the sprite identifier.
tk2dSpriteDefinition CurrentSprite [get]
 Gets the current sprite definition.

Detailed Description

Sprite implementation which plays and maintains animations.


Member Enumeration Documentation

enum tk2dBaseSprite.Anchor [inherited]

Anchor. NOTE: The order in this enum is deliberate, to initialize at LowerLeft for backwards compatibility. This is also the reason it is local here. Other Anchor enums are NOT compatbile. Do not cast.


Member Function Documentation

static tk2dSprite tk2dSprite.AddComponent ( GameObject  go,
tk2dSpriteCollectionData  spriteCollection,
int  spriteId 
) [static, inherited]

Adds a tk2dSprite as a component to the gameObject passed in, setting up necessary parameters and building geometry. Convenience alias of tk2dBaseSprite.AddComponent<tk2dSprite>(...).

static tk2dAnimatedSprite tk2dAnimatedSprite.AddComponent ( GameObject  go,
tk2dSpriteAnimation  anim,
int  clipId 
) [static]

Adds a tk2dAnimatedSprite as a component to the gameObject passed in, setting up necessary parameters and building geometry.

static tk2dSprite tk2dSprite.AddComponent ( GameObject  go,
tk2dSpriteCollectionData  spriteCollection,
string  spriteName 
) [static, inherited]

Adds a tk2dSprite as a component to the gameObject passed in, setting up necessary parameters and building geometry. Convenience alias of tk2dBaseSprite.AddComponent<tk2dSprite>(...).

static T tk2dBaseSprite.AddComponent< T > ( GameObject  go,
tk2dSpriteCollectionData  spriteCollection,
int  spriteId 
) [static, inherited]

Adds a tk2dBaseSprite derived class as a component to the gameObject passed in, setting up necessary parameters and building geometry.

Type Constraints
T :tk2dBaseSprite 
static T tk2dBaseSprite.AddComponent< T > ( GameObject  go,
tk2dSpriteCollectionData  spriteCollection,
string  spriteName 
) [static, inherited]

Adds a tk2dBaseSprite derived class as a component to the gameObject passed in, setting up necessary parameters and building geometry. Shorthand using sprite name.

Type Constraints
T :tk2dBaseSprite 
delegate void tk2dAnimatedSprite.AnimationCompleteDelegate ( tk2dAnimatedSprite  sprite,
int  clipId 
)

Animation complete delegate.

Animation event delegate.

override void tk2dSprite.Build ( ) [virtual, inherited]

Rebuilds the mesh data for this sprite. Not usually necessary to call this, unless some internal states are modified.

Implements tk2dBaseSprite.

static GameObject tk2dSprite.CreateFromTexture ( Texture  texture,
tk2dRuntime.SpriteCollectionSize  size,
Rect  region,
Vector2  anchor 
) [static, inherited]

Create a sprite (and gameObject) displaying the region of the texture specified. Use tk2dSpriteCollectionData.CreateFromTexture if you need to create a sprite collection with multiple sprites. Convenience alias of tk2dBaseSprite.CreateFromTexture<tk2dSprite>(...)

static GameObject tk2dBaseSprite.CreateFromTexture< T > ( Texture  texture,
tk2dRuntime.SpriteCollectionSize  size,
Rect  region,
Vector2  anchor 
) [static, inherited]

Create a sprite (and gameObject) displaying the region of the texture specified. Use tk2dSpriteCollectionData.CreateFromTexture if you need to create a sprite collection with multiple sprites.

Type Constraints
T :tk2dBaseSprite 
void tk2dBaseSprite.FlipX ( ) [inherited]

Flips the sprite horizontally.

void tk2dBaseSprite.FlipY ( ) [inherited]

Flips the sprite vertically.

Bounds tk2dBaseSprite.GetBounds ( ) [inherited]

Gets the local space bounds of the sprite.

Returns:
Local space bounds

Resolves an animation clip by name and returns a reference to it. This is a convenient alias to tk2dSpriteAnimation.GetClipByName

Returns:
tk2dSpriteAnimationClip reference, null if not found
Parameters:
nameCase sensitive clip name, as defined in tk2dSpriteAnimationClip.
int tk2dAnimatedSprite.GetClipIdByName ( string  name)

Resolves an animation clip by name and returns a unique id. This is a convenient alias to tk2dSpriteAnimation.GetClipIdByName

Returns:
Unique Animation Clip Id.
Parameters:
nameCase sensitive clip name, as defined in tk2dSpriteAnimationClip.

Gets the current sprite definition.

Returns:
tk2dSpriteDefinition for the currently active sprite.
int tk2dBaseSprite.GetSpriteIdByName ( string  name) [inherited]

Resolves a sprite name and returns a unique id for the sprite. Convenience alias of tk2dSpriteCollectionData.GetSpriteIdByName

Returns:
Unique Sprite Id.
Parameters:
nameCase sensitive sprite name, as defined in the sprite collection. This is usually the source filename excluding the extension
Bounds tk2dBaseSprite.GetUntrimmedBounds ( ) [inherited]

Gets untrimmed local space bounds of the sprite. This is the size of the sprite before 2D Toolkit trims away empty space in the sprite. Use this when you need to position sprites in a grid, etc, when the trimmed bounds is not sufficient.

Returns:
Local space untrimmed bounds

Is a clip currently playing? Obselete, use tk2dSpriteAnimation.Playing instead.

bool tk2dAnimatedSprite.IsPlaying ( string  name)

Is the named clip currently active & playing?

Is this clip currently active & playing?

void tk2dBaseSprite.MakePixelPerfect ( ) [inherited]

Makes the sprite pixel perfect to the active camera. Automatically detects tk2dCamera if present Otherwise uses Camera.main.

Pause the currently playing clip. Will do nothing if the clip is currently paused.

Play the active clip. Will restart the clip if called again. Will restart the clip at clipStartTime if called while the clip is playing.

void tk2dAnimatedSprite.Play ( float  clipStartTime)

Play the active clip, starting "clipStartTime" seconds into the clip. Will restart the clip at clipStartTime if called while the clip is playing.

void tk2dAnimatedSprite.Play ( string  name)

Play the specified clip. Will restart the clip at clipStartTime if called while the clip is playing.

Parameters:
nameName of clip. Try to cache the animation clip Id and use that instead for performance.
void tk2dAnimatedSprite.Play ( string  name,
float  clipStartTime 
)

Play the specified clip, starting "clipStartTime" seconds into the clip. Will restart the clip at clipStartTime if called while the clip is playing.

Parameters:
nameName of clip. Try to cache the animation clip Id and use that instead for performance.
clipStartTimeClip start time in seconds.
void tk2dAnimatedSprite.Play ( int  id)

Play the clip specified by identifier. Will restart the clip at clipStartTime if called while the clip is playing.

Parameters:
idUse GetClipIdByName to resolve a named clip id
void tk2dAnimatedSprite.Play ( int  clipId,
float  clipStartTime 
)

Play the clip specified by identifier. Will restart the clip at clipStartTime if called while the clip is playing.

Parameters:
idUse GetClipIdByName to resolve a named clip id
clipStartTimeClip start time in seconds.
void tk2dAnimatedSprite.Play ( tk2dSpriteAnimationClip  clip,
float  clipStartTime 
)

Play the clip specified by identifier. Will restart the clip at clipStartTime if called while the clip is playing.

Parameters:
clipThe clip to play.
clipStartTimeClip start time in seconds. A value of DefaultFps will start the clip from the beginning
void tk2dAnimatedSprite.Play ( tk2dSpriteAnimationClip  clip,
float  clipStartTime,
float  overrideFps 
)

Play the clip specified by identifier. Will restart the clip at clipStartTime if called while the clip is playing. No defaults to play nice with default MonoDevelop configuration.

Parameters:
clipThe clip to play.
clipStartTimeClip start time in seconds. A value of DefaultFps will start the clip from the beginning
overrideFpsOverriden framerate of clip. Set to 0 to use default
void tk2dAnimatedSprite.PlayFromFrame ( int  frame)

Play the active clip, starting at the frame specified. Will restart the clip at frame if called while the clip is playing.

void tk2dAnimatedSprite.PlayFromFrame ( string  name,
int  frame 
)

Play the specified clip, starting at the frame specified. Will restart the clip at frame if called while the clip is playing.

Parameters:
nameName of clip. Try to cache the animation clip Id and use that instead for performance.
frameFrame to start playing from.
void tk2dAnimatedSprite.PlayFromFrame ( int  id,
int  frame 
)

Play the clip specified by identifier, starting at the specified frame. Will restart the clip at clipStartTime if called while the clip is playing.

Parameters:
idUse GetClipIdByName to resolve a named clip id
frameFrame to start from.

Resume the currently paused clip. Will do nothing if the clip hasn't been paused.

void tk2dAnimatedSprite.SetFrame ( int  currFrame)

Sets the current frame. The animation will wrap if the selected frame exceeds the number of frames in the clip. This variant WILL trigger an event if the current frame has a trigger defined.

void tk2dAnimatedSprite.SetFrame ( int  currFrame,
bool  triggerEvent 
)

Sets the current frame. The animation will wrap if the selected frame exceeds the number of frames in the clip.

void tk2dBaseSprite.SetSprite ( int  newSpriteId) [inherited]

Sets the sprite by identifier.

bool tk2dBaseSprite.SetSprite ( string  spriteName) [inherited]

Sets the sprite by name. The sprite will be selected from the current collection.

void tk2dBaseSprite.SetSprite ( tk2dSpriteCollectionData  newCollection,
int  spriteId 
) [inherited]

Sets sprite by identifier from the new collection.

bool tk2dBaseSprite.SetSprite ( tk2dSpriteCollectionData  newCollection,
string  spriteName 
) [inherited]

Sets sprite by name from the new collection.

Stop the currently playing clip.

Stops the currently playing animation and reset to the first frame in the animation.

void tk2dBaseSprite.SwitchCollectionAndSprite ( tk2dSpriteCollectionData  newCollection,
int  newSpriteId 
) [inherited]

Switches the sprite collection and sprite. Simply set the spriteId property when you don't need to switch the sprite collection. This will be deprecated in a future release, use SetSprite instead.

Parameters:
newCollectionA reference to the sprite collection to switch to.
newSpriteIdNew sprite identifier.
bool tk2dBaseSprite.SwitchCollectionAndSprite ( tk2dSpriteCollectionData  newCollection,
string  spriteName 
) [inherited]

Switches the sprite collection and sprite. Simply set the spriteId property when you don't need to switch the sprite collection. This will be deprecated in a future release, use SetSprite instead.

Parameters:
newCollectionA reference to the sprite collection to switch to.
spriteNameSprite name.

Member Data Documentation

Animation complete event. This is called when the animation has completed playing. Will not trigger on looped animations.

Animation event. This is called when the frame displayed has tk2dSpriteAnimationFrame.triggerEvent set. The triggering frame is passed to the delegate, and the eventInfo / Int / Float can be extracted from there.

BoxCollider tk2dBaseSprite.boxCollider = null [inherited]

Internal cached version of the box collider created for this sprite, if present.

Currently playing/active clip.

Interface option to create an animated box collider for this animated sprite.

MeshCollider tk2dBaseSprite.meshCollider = null [inherited]

Internal cached version of the mesh collider created for this sprite, if present.

bool tk2dBaseSprite.pixelPerfect = false [inherited]

Specifies if this sprite is kept pixel perfect.

Interface option to play the animation automatically when instantiated / game is started. Useful for background looping animations.


Property Documentation

float tk2dAnimatedSprite.ClipFps [get, set]

Current frame rate of the playing clip. May have been overriden by the user. Set to 0 to default to the clips fps.

The current clip time in seconds.

Deprecation warning: the set accessor will be removed in a future version. Use SwitchCollectionAndSprite when you need to switch sprite collection.

Color tk2dBaseSprite.color [get, set, inherited]

Gets or sets the color.

Please note the range for a Unity Color is 0..1 and not 0..255.

The currently active or playing tk2dSpriteAnimationClip

Gets the current sprite definition.

Returns:
tk2dSpriteDefinition for the currently active sprite.
bool tk2dAnimatedSprite.g_paused [static, get, set]

Globally pause all animated sprites.

bool tk2dAnimatedSprite.Paused [get, set]

Get or set pause state on this current sprite.

Is a clip currently playing? Will return true if the clip is playing, but is paused.

Vector3 tk2dBaseSprite.scale [get, set, inherited]

Gets or sets the scale.

Use the sprite scale method as opposed to transform.localScale to avoid breaking dynamic batching.

int tk2dBaseSprite.spriteId [get, set, inherited]

Gets or sets the sprite identifier.

The spriteId is a unique number identifying each sprite. Use GetSpriteIdByName to resolve an identifier from the current sprite collection.