Hello Guest

Author Topic: How can I tween alpha on tk2dAnimatedSprite  (Read 10083 times)

summfire

  • Newbie
  • *
  • Posts: 6
    • View Profile
How can I tween alpha on tk2dAnimatedSprite
« on: May 27, 2013, 11:26:57 am »
Hi,

I tried to tween aplha on a tk2dAnimatedSprite sprite but every time if the frame of the animation changed then it will switched back to 1. Just want to know what is the right way to tween alpha on it.

Thanks a lot

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: How can I tween alpha on tk2dAnimatedSprite
« Reply #1 on: May 27, 2013, 11:56:46 am »
Get hotween / gokit / etc.
Here is a post about how you fade with HOTween
http://unikronsoftware.com/2dtoolkit/forum/index.php/topic,995.msg4783.html#msg4783

summfire

  • Newbie
  • *
  • Posts: 6
    • View Profile
Re: How can I tween alpha on tk2dAnimatedSprite
« Reply #2 on: May 27, 2013, 12:19:48 pm »
Thanks. I tried to use it but still cannot tween the alpha. Could you give me an examle. I want to tween tk2dAnimatedSprite, not tk2dSprite

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: How can I tween alpha on tk2dAnimatedSprite
« Reply #3 on: May 27, 2013, 12:23:18 pm »
tk2dAnimatedSprite is the same as a tk2dSprite.  What works with a tk2dSprite will work with an animated sprite - try it with the sprites included in tk2d - it definitely does work.

summfire

  • Newbie
  • *
  • Posts: 6
    • View Profile
Re: How can I tween alpha on tk2dAnimatedSprite
« Reply #4 on: May 27, 2013, 12:36:27 pm »
tk2dAnimatedSprite sprite = role.GetComponent<tk2dAnimatedSprite>();
HOTween.To(sprite, 1000f, new TweenParms().Prop("color", new Color(sprite.color.r, sprite.color.g, sprite.color.b, 0.0f)));

is this correct? It still doesn't work

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: How can I tween alpha on tk2dAnimatedSprite
« Reply #5 on: May 27, 2013, 12:43:09 pm »
Why 1000? Thats gonna take 1000 seconds, which is  16 minutes to fade out...
Did you wait 16 minutes?  :o

summfire

  • Newbie
  • *
  • Posts: 6
    • View Profile
Re: How can I tween alpha on tk2dAnimatedSprite
« Reply #6 on: May 27, 2013, 12:49:21 pm »
ops, it was set to 1f but I changed it to 1000f since 1f doesn't work I just changed to a random number. I changed it back to 1f but still doesn't work...

Do you know what's wrong with my code? Thx

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: How can I tween alpha on tk2dAnimatedSprite
« Reply #7 on: May 27, 2013, 01:05:57 pm »
Do you get any errors in the console, etc?
Try this on a basic sprite included in tk2d - eg. demoanimations. Eg. something like this DEFINITELY works.

         tk2dBaseSprite sprite = gameObject.GetComponent<tk2dBaseSprite>();
         HOTween.To(sprite, 2.0f, new TweenParms().Prop("color", new Color(sprite.color.r, sprite.color.g, sprite.color.b, 0.0f)));


You don't even need to get the tk2dAnimatedSprite, the base sprite will suffice.

summfire

  • Newbie
  • *
  • Posts: 6
    • View Profile
Re: How can I tween alpha on tk2dAnimatedSprite
« Reply #8 on: May 27, 2013, 02:00:27 pm »
no errors at all. I tried your code as well but still doesn't work. It really annoys me.

I even tried to modified it directly by the method I wrote below

Code: [Select]

       public void SetAlpha(float alpha)
{
Material material = role.GetComponent<Renderer>().material;
Color color = material.GetColor("_Tint");
color.a = alpha;
material.SetColor("_Tint", color);
}

It works perfectly with non animated sprite but not animated one...

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: How can I tween alpha on tk2dAnimatedSprite
« Reply #9 on: May 27, 2013, 02:09:00 pm »
You should never do what you're doing there, that will simply create many many copies of materials, and will massively increase draw calls when you have a few of them on screen.

That code from the previous post definitely works with the built in sample sprite collection animation. I cut and pasted it from a project where it was working in the scene. If it doesn't work, you're definitely missing something. Did you modify the material/shader used in your sprites? The normal tk2d shaders don't use a _Tint property.

If you want me to look at what is wrong email support with your project, but I strongly recommend working it out - I can confirm it definitely does work when applied to the tk2d animated sprite sample (the one with the numbers counting up), so its not like its a suggestion that may or may not work - it definitely will work.

summfire

  • Newbie
  • *
  • Posts: 6
    • View Profile
Re: How can I tween alpha on tk2dAnimatedSprite
« Reply #10 on: May 27, 2013, 02:56:03 pm »
Thx. I'll try to solve this problem. Will update if I can figure out the actual issue.