78 lines
2.1 KiB
C#
78 lines
2.1 KiB
C#
using Microsoft.Xna.Framework;
|
|
using Microsoft.Xna.Framework.Graphics;
|
|
using RhythmBullet.Zer01HD.Utilities.UI;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Diagnostics;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace RhythmBullet.Zer01HD.Game.Screens.Transitions
|
|
{
|
|
internal class FadeInTransition : IDisposable
|
|
{
|
|
private const float RATE = 0.3f;
|
|
public readonly Texture2D curtain;
|
|
public Rectangle curtainSize;
|
|
private Color color;
|
|
private float progR, progG, progB, progA;
|
|
private float rR, rG, rB, rA;
|
|
internal FadeInTransition(GraphicsDevice graphicsDevice, Color startColor)
|
|
{
|
|
curtain = new Texture2D(graphicsDevice, 1, 1);
|
|
curtain.SetData(new[] { Color.White });
|
|
|
|
color = startColor;
|
|
}
|
|
|
|
internal void Init(Rectangle dimensions)
|
|
{
|
|
curtainSize = dimensions;
|
|
rR = (0 - color.R) / RATE;
|
|
rG = (0 - color.G) / RATE;
|
|
rB = (0 - color.B) / RATE;
|
|
rA = (0 - color.A) / RATE;
|
|
|
|
progA = color.A;
|
|
progR = color.R;
|
|
progG = color.G;
|
|
progB = color.B;
|
|
}
|
|
|
|
internal bool Fade(float deltaf)
|
|
{
|
|
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 false;
|
|
}
|
|
|
|
internal void Draw(SpriteBatch batch)
|
|
{
|
|
if (curtain != null)
|
|
{
|
|
batch.Draw(curtain, curtainSize, color);
|
|
}
|
|
}
|
|
|
|
public void Dispose()
|
|
{
|
|
curtain.Dispose();
|
|
}
|
|
}
|
|
}
|