I have problem with animate image, when transforming from transparent image to opaque image.
If I animate image from opaque image to transparent image, works fine. But, if I animate image from transparent image to opaque image, It's non-functional.(that's problem)
Sample code:
Animate from opaque to transparent: (all is OK, it's functional)
//Define variables (in construct):
float AlphaTime = 3500f; // total animate time (at milliseconds)
float AlphaTimeSubtract = 3500f; // at milliseconds
Color color = Color.White;
//Update method:
AlphaTimeSubtract -= (float)(gameTime.ElapsedGameTime.TotalMilliseconds); // abate number of elapsed time (for milliseconds)
color *= MathHelper.Clamp(AlphaTimeSubtract / AlphaTime, 0, 1);
//Draw merhod:
spriteBatch.Draw(texture, position, color);
Animate from transparent to opaque : (that is problem, it is non-functional) !!!
Result is invisible sprite!(it's wrong)
Correct result should be: animate sprite from transparent to opaque.
//Define variables (in construct):
float AlphaTime = 3500f; // total animate time (at milliseconds)
float AlphaTimeSubtract = 3500f; // at milliseconds
Color color = Color.White;
//Update method:
AlphaTimeSubtract -= (float)(gameTime.ElapsedGameTime.TotalMilliseconds); // abate number of elapsed time (for milliseconds)
color *= MathHelper.Clamp(Math.Abs(AlphaTimeSubtract - AlphaTime ) / AlphaTime , 0, 1);
//Draw merhod:
spriteBatch.Draw(texture, position, color);
Math.Abs()
: return absolute value
What am I doing wrong?