Search Unity

LeanTween.alpha with 2D sprites doesn't work.

Discussion in '2D' started by BenoitFreslon, Jan 18, 2014.

  1. BenoitFreslon

    BenoitFreslon

    Joined:
    Jan 16, 2013
    Posts:
    166
    Hello,

    I'm using the LeanTween library.

    But unfortunatly the alpha method doens't work.
    I want a fadein and a fadeout effect but I can't use this method on 2D sprite.

    Any tips?

    Thanks.
     
  2. zombiegorilla

    zombiegorilla

    Moderator

    Joined:
    May 8, 2012
    Posts:
    9,052
    You can use use the value method, which lets you tween any value. So a very simplified version of this (attached to the sprite you want to fade would look something like this:

    Code (csharp):
    1.  
    2.     SpriteRenderer my_sprite;
    3.  
    4.     void Awake()
    5.     {
    6.         my_sprite = GetComponent<SpriteRenderer>() as SpriteRenderer;
    7.     }
    8.    
    9.     public void FadeIn()
    10.     {
    11.         LeanTween.value( gameObject, setSpriteAlpha, 0f, 1f, 1f );
    12.     }
    13.    
    14.     public void FadeOut()
    15.     {
    16.         LeanTween.value( gameObject, setSpriteAlpha, 1f, 0f, 1f );
    17.     }
    18.    
    19.     public void setSpriteAlpha( float val )
    20.     {
    21.         my_sprite.color = new Color(1f,1f,1f,val);
    22.     }
    23.  
     
    ridexpl likes this.
  3. dentedpixel

    dentedpixel

    Joined:
    Jul 15, 2012
    Posts:
    683
    I just wanted to update everyone, that the latest version on Github has fixed this issue. You can now tween a 2d sprite. This feature will eventually get pushed to the Asset Store as well, I will be pushing an updated version probably this week.

    Cheers,
    Russ
     
    ridexpl likes this.
  4. zombiegorilla

    zombiegorilla

    Moderator

    Joined:
    May 8, 2012
    Posts:
    9,052
    Very cool.