KeyboardState lastKeyState;
bool isFadeIn = false;
float alphaValue = 0.0f;
protected override void Update(GameTime gameTime)
{
KeyboardState ks = Keyboard.GetState();
// TODO: Add your update logic here
if (gps.Buttons.Back == ButtonState.Pressed)
this.Exit();
if(ks.IsKeyUp(Keys.Space) && lastKeyState.IsKeyDown(Keys.Space))
{
isFadeIn = true;
}
if (isFadeIn)
{
alphaValue += (float)gameTime.ElapsedGameTime.TotalMilliseconds;
if (alphaValue >= 1.0f)
{
alphaValue = 1.0f;
isFadeIn = false;
}
}
else if (alphaValue > 0.0f)
{
alphaValue -= (float)gameTime.ElapsedGameTime.TotalMilliseconds;
if (alphaValue <= 0.0f) alphaValue = 0.0f;
}
base.Update(gameTime);
}
protected override void Draw(GameTime gameTime)
{
GraphicsDevice.Clear(Color.CornflowerBlue);
// TODO: Add your drawing code here
spriteBatch.Begin();
spriteBatch.Draw(textureSprite, destRect, sourceRect, new Color(Color.White, alphaValue));
spriteBatch.End();
base.Draw(gameTime);
}
Isso é um exemplo pratico, e funciona.