2D Toolkit Forum
2D Toolkit => Support => Topic started by: DarkSlash on April 29, 2015, 10:26:59 pm
-
I want to create a fade in/out class (don't know why the ones in iTween doesn't work for me). I wrote this code but this doesn't affect the alpha color of the sprite. What I'm doing wrong?
public int speed = 4;
bool isFadeIn = false;
bool isFadeOut = false;
float alphaColor = 0;
Color spriteColor;
void Update()
{
if(isFadeIn == true && alphaColor < 255)
{
alphaColor += Time.deltaTime * speed;
spriteColor.a = alphaColor;
GetComponent<tk2dSprite>().color= spriteColor;
}
}
public void FadeIn()
{
isFadeIn = true;
}
public void FadeOut()
{
isFadeOut = true;
}
-
The range for the Color type is 0..1 not 0..255
-
Don't understand what you're saying. Is not this?
-
Look in the unity docs.
http://docs.unity3d.com/ScriptReference/Color.html
-
I understand that. The question is how to access to the alpha color property in the script. I tried GetComponent<tk2dSprite>().color.a and doesn't work. Also doesn't respond when I apply a new color with GetComponent<tk2dSprite>().color = colorVariable. So, how is the correct way to access to a sprite color?
-
if(isFadeIn == true && alphaColor < 255)
{
alphaColor += Time.deltaTime * speed;
spriteColor.a = alphaColor;
GetComponent<tk2dSprite>().color= spriteColor;
}
You're moving alphaColor from 0..255. The range for alpha is 0..1.