Hello Guest

Author Topic: Remove sprite after finishing animation  (Read 4280 times)

AndyJ710

  • Newbie
  • *
  • Posts: 4
    • View Profile
Remove sprite after finishing animation
« on: October 08, 2013, 04:50:51 pm »
I'm definitely a newb so apologize if this is a redundant question (though I've searched the FAQs and this forum and can't find the answer)...

I'm trying to remove a sprite after I instantiate it and it is completed animating. I am using javascript to do this. I am able to instantiate the sprite and then animate it but not sure what to do once it's done animating. How do I remove the game object?

For example, I have coins that I want to animate sparks and particles at the location of the coin once the coin is collected.

I'm mainly afraid that if I use a blank PNG frame at the end of the spark animation (so it's visibly gone to the user) that collecting too many coins will start to hinder performance because of all the new (invisible) sprites being used.


Thanks for any tips anyone can think of!!!

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Remove sprite after finishing animation
« Reply #1 on: October 08, 2013, 06:45:52 pm »
You need to attach a script that destroys it when the animation completes. Its the animationCompleteDelegate that you want to hook into. Here's an example of hooking into that delegate with JS.
http://unikronsoftware.com/2dtoolkit/doc/latest/tutorial/scripting_a_sprite_animator.html
You'd probably want to Destroy( gameObject ); from the delegate.

AndyJ710

  • Newbie
  • *
  • Posts: 4
    • View Profile
Re: Remove sprite after finishing animation
« Reply #2 on: October 09, 2013, 12:39:14 am »
Awesome. Thanks for the quick response!

That link/tip worked like a charm.