Hello Guest

Author Topic: Help with Returning to a Sprite after Animation Ends  (Read 4237 times)

ZBexperiments

  • Newbie
  • *
  • Posts: 2
    • View Profile
Help with Returning to a Sprite after Animation Ends
« on: September 27, 2013, 09:15:01 pm »
Hello,

I really don't understand how to do something after an animation ends.
I want to set the sprite to the same one I had before I trigger the animation.
So there would be a sprite, then I would trigger an animation, and then it would go back to the sprite.

The reference documents aren't making sense to me regarding the animation scripting.
I know I have to use AnimationCompleted, but I dont know how to set it up the correct way.

Thanks

profanicus

  • 2D Toolkit
  • Full Member
  • *
  • Posts: 167
    • View Profile
Re: Help with Returning to a Sprite after Animation Ends
« Reply #1 on: September 27, 2013, 10:45:20 pm »
The docs here show how it is done.

It uses delegates, which basically allow a method to be assigned as a parameter, and that method is then called when the animation finishes.

Here are the relevant bits from the above docs. You set up a method with the required signature:

Code: [Select]
void HitCompleteDelegate(tk2dSpriteAnimator sprite, tk2dSpriteAnimationClip clip) {
        //code in here will be executed when your anim is finished
    }

And then after you start your animation, you tell it to call the above method when it's finished, like so:

Code: [Select]
anim.AnimationCompleted = HitCompleteDelegate;

ZBexperiments

  • Newbie
  • *
  • Posts: 2
    • View Profile
Re: Help with Returning to a Sprite after Animation Ends
« Reply #2 on: September 27, 2013, 11:28:30 pm »
Thanks for the help.

I think I have that part figured out now.

But when I test my game, the animation doesnt play.
I get an error saying "Object reference not set to an instance of an object".
Its something wrong with this line of code, but its exactly how the docs show how to do it.

anim.Play("BowAnim");

I have no idea why it isnt playing the animation.

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Help with Returning to a Sprite after Animation Ends
« Reply #3 on: September 28, 2013, 10:11:02 am »
That implies the library isn't assigned, or perhaps is null? What is anim.Library?