Hello Guest

Author Topic: Limitations of .AnimationCompleted - should work with PingPong & 1 frame anims?  (Read 3276 times)

AnnaM

  • Newbie
  • *
  • Posts: 1
    • View Profile
EDIT - I've just gone back to Unity and this is now working with a 1 frame animation (must've not committed something!) although still not the ping pong - editing the question accordingly.

I've created a small script to run through an animation when a UIItem is pressed which should then switch back to the object's default animation.

It works fine when the touch animation is set to Once, and has multiple frames. But does not work if the touch animation    is set to PingPong.  It continues to run the touch animation forever and never goes back to the default.

Should .AnimationCompleted work here, or should I use other methods to handle these cases?
I have pasted my script below for reference.

Thanks!

public tk2dSprite animatedSprite;
   public string myTouchAnim;
   public string myDefaultAnim;
   public bool singleAnim;

   tk2dSpriteAnimator spriteAnimation;

   void Start () {
      spriteAnimation = animatedSprite.GetComponent<tk2dSpriteAnimator>();
   }

   void ReturnToDefaultAnim (tk2dSpriteAnimator sprite, tk2dSpriteAnimationClip clip){
      spriteAnimation.Play (myDefaultAnim);
   }

   void ButtonDown () {
      if (!spriteAnimation.IsPlaying(myTouchAnim)) {
         spriteAnimation.Play(myTouchAnim);
         spriteAnimation.AnimationCompleted=ReturnToDefaultAnim;
      }
}
« Last Edit: April 05, 2014, 05:16:41 pm by AnnaM »

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
PingPong is like looped, so will never "complete" playing. You could use events to detect when it has played back, but you might as well add the frames in reverse to make it easier to do so.