0

我正试图让我的启动画面淡入黑色。我意识到它会淡入GraphicsDevice.Clear(Color.White);默认更新方法的默认行中清除屏幕的任何颜色。当我把它变成白色时,我的图像会变成白色,这是有道理的。所以我将它从白色更改为黑色,但我的图像不再褪色或看起来不像。

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 是应用于启动画面的纹理的颜色,定义如下,public static Color blender = new Color(255, 255, 255);

4

1 回答 1

1

Xna 4.0 使用预乘 alpha,因此您的代码不正确....您应该将颜色乘以 alpha...但我会做类似的事情:

 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
          }
     }
 }
于 2013-04-20T23:42:53.117 回答