Hello Guest

Author Topic: Fade out during tk2dSpriteAnimation ?  (Read 4893 times)

mrkake

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 17
    • View Profile
Fade out during tk2dSpriteAnimation ?
« on: November 16, 2015, 02:02:44 am »
I can't figure out how to do this easily.

I read a few other threads, and it seems fairly straight forward to get a sprite to fade out, lets just say set the alpha to 50% to be simple:

just on the tk2dsprite:
Color color = sprite.color;
color.a = newAlpha; // calculated elsewhere
sprite.color = color;

This actually works fine, the problem is, that during tk2dSpriteAnimation, every time the frame changes, the material is reset. Additionally the material is somewhere cached and every instance of the animation fades out at the same rate.

Even if I just run the fade out code on a single animation, every instance of that animation which is playing starts to fade out.

Is it possible to get a method to do a fadeout? Basically, I want to specific the start % and end % of the fadeout.  i.e.  start fading out 80% of the way through the animation and finish fading out 100% of the way through the animation.

I know that I can get my code working if I created a new material for every frame (and for every instance) of the animation and reset the material whenever SpriteChanged event fires. However, this is a LOT of materials when we are talking about the types of effects I want to fade out.

The other argument could be that the fade should be in the animation itself. This is the next step if its really not possible in the code. However, Currently, I have one really big animation, for example a giant explosion. What I would really love to be able to do is have small and large explosions all using the same sprite sequence. Then, what I can say is "play from this frame to that frame" with a fade starting at a certain percentage... if this worked, I could use a single actual animation (sprite sheet) , and create many many many different animations.

Anyway, I don't think it's currently possible in 2d toolkit. But please let me know if it is or any thoughts?

Thanks!

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Fade out during tk2dSpriteAnimation ?
« Reply #1 on: November 17, 2015, 11:03:56 pm »
The easiest way is to use something like HOTween / DOTween. Its fast, gets the job done and pretty easy to implement. HOTween comes with 2D Toolkit adapter built in too, not sure about DOTween. Importantly - please don't animate materials, its not efficient at all.

mrkake

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 17
    • View Profile
Re: Fade out during tk2dSpriteAnimation ?
« Reply #2 on: November 21, 2015, 11:59:57 pm »
Hey thanks! It took me a bit to understand , though it's really quite simple in the end, and I had to buy the pro version of DOTween for $15, but, its working !!!

Very nice, thanks :)