Animation API

Let' create MonoBehaviour script and attach it to any game object. Drag and drop Texture Packer Animation to the public anim filed of our MonoBehaviour  script.

public TPSpriteAnimation anim;

 

 

Methods:

Play Animation

anim.Play();

 

Stop Animation

anim.Stop();

 

Go to frame with index 2 and play animation

anim.GoToAndPlay(2);

 

Got Frame with index 2 and stop animation

anim.GoToAndStop(2);

 

Fade In / Fade Out

anim.AnimateSpriteOpacity(anim.opacity, 0f, 0.5f);
anim.AnimateSpriteOpacity(anim.opacity, 1f, 0.5f);

 

Events:

Enter Frame 

anim.OnEnterFrame += OnEnterFrame;

void OnEnterFrame (int index) {
	//Debug.Log("Fame index: " + index);
}

 


Animation Complete 

anim.OnAnimationComplete += OnAnimationComplete;

void OnAnimationComplete (){
	Debug.Log("OnAnimationComplete");
}

 

Note: Animation complete will be fired only for animation without loop.

 

Fade Animation Complete 

anim.OnFadeAnimationComplete += OnFadeAnimationComplete;
void OnFadeAnimationComplete (){
	Debug.Log("OnFadeComplete");
}

 

Full example can be found under the AnimationControllerExample example scene.