XNA 4 c# -非Alpha混合到黑色
本文关键字:混合 黑色 Alpha XNA | 更新日期: 2023-09-27 18:10:14
我想让我的启动屏幕逐渐变黑。我意识到它会淡入默认更新方法中默认行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);
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
}
}
}