rhythmbullet/RhythmBullet/Zer01HD/Screens/Transitions/FadeAwayTransition.cs

93 lines
2.5 KiB
C#
Raw Normal View History

2018-11-01 06:09:10 +00:00
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using RhythmBullet.Zer01HD.Utilities.UI;
using RhythmBullet.Zer01HD.Utilities.ScreenSystem;
2018-11-01 06:09:10 +00:00
using System;
using System.Collections.Generic;
using System.Diagnostics;
2018-11-01 06:09:10 +00:00
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace RhythmBullet.Zer01HD.Screens.Transitions
2018-11-01 06:09:10 +00:00
{
internal class FadeAwayTransition : IDisposable, ITransition
2018-11-01 06:09:10 +00:00
{
private float time;
public Texture2D curtain;
public Rectangle curtainSize;
private Color color;
2018-11-01 06:09:10 +00:00
private float progR, progG, progB, progA;
private float rR, rG, rB, rA;
2018-11-01 06:09:10 +00:00
internal FadeAwayTransition(float time)
{
this.time = time;
}
public void InitiateTransition(Rectangle dimensions)
{
curtainSize = dimensions;
color = Color.White;
rR = (0 - 254) / time;
rG = (0 - 254) / time;
rB = (0 - 254) / time;
rA = (0 - 254) / time;
progA = color.A;
progR = color.R;
progG = color.G;
progB = color.B;
}
2018-11-01 06:09:10 +00:00
private bool Fade(float deltaf)
2018-11-01 06:09:10 +00:00
{
if (progR > 0 || progG > 0 || progB > 0)
{
progR += rR * deltaf;
progR = Math.Max(progR, 0);
progG += rG * deltaf;
progG = Math.Max(progG, 0);
progB += rB * deltaf;
progB = Math.Max(progB, 0);
progA += rA * deltaf;
progA = Math.Max(progA, 0);
color.R = (byte)progR;
color.G = (byte)progG;
color.B = (byte)progB;
color.A = (byte)progA;
return false;
}
return true;
}
public void DrawTransition(SpriteBatch batch)
{
if (curtain != null)
{
batch.Draw(curtain, curtainSize, color);
}
2018-11-01 06:09:10 +00:00
}
public void Dispose()
{
curtain.Dispose();
}
public bool EnteringTransition(double delta, bool assetsLoaded)
{
return Fade((float)delta);
}
public bool ExitingTransition(double delta, bool assetsLoaded)
{
return Fade((float)delta);
}
public void UpdatePreviousScreenFrame(RenderTarget2D previousScreenFrame)
{
curtain = previousScreenFrame;
}
2018-11-01 06:09:10 +00:00
}
}