我正试图让我的启动画面淡入黑色。我意识到它会在默认更新方法的默认行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);
答案 0 :(得分: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
}
}
}