Reputation: 284
I'm trying to have my Splash Screen fade into black. I realized it fades into whatever color the screen is cleared with in the default line GraphicsDevice.Clear(Color.White);
in the default update method. When I make it white, my image fades into white, which makes sense. So I changed it from White to Black but my image no longer fades at all or doesn't look like it.
public void SplashUpdate(GameTime theTime)
{
gameTime = theTime;
if ( theTime.TotalGameTime.Seconds > 1.4 )
{
Draw.blender.A --;
if (Draw.blender.A == 0)
{
game1.currentState = PixeBlastGame.Game1.GameState.gameSplash;
MediaPlayer.Play(Game1.sMenu);
}
}
}
blender is the color that is applied to my Texture for the splash screen and is defined like so, public static Color blender = new Color(255, 255, 255);
Upvotes: 0
Views: 989
Reputation: 5762
Xna 4.0 uses premultiplied alpha so your code is not right.... you should multiply the color by the alpha... but i'd do something similar to this:
float fadeDuration = 1;
float fadeStart = 1.4f;
float timeElapsed = 0;
Color StartColor = Color.White;
Color EndColor = Color.Transparent;
void Update(GameTime time)
{
float secs = (float) time.ElapsedTime.TotalSeconds;
timeElapsed += secs;
if (timeElapsed>fadeStart)
{
// Value in 0..1 range
var alpha =(timeElapsed - fadeStart)/fadeDuration;
Draw.Blender = Color.White * (1 - alpha);
// or Draw.Blender = Color.Lerp(StartColor, EndColor, alpha);
if (timeElapsed>fadeDuration + fadeStart)
{
Draw.Blender = EndColor;
// Change state
}
}
}
Upvotes: 1