created new fade in transition

This commit is contained in:
Harrison Deng 2018-11-01 01:09:10 -05:00
parent 00ca68662c
commit 353843476a

View File

@ -0,0 +1,65 @@
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using RhythmBullet.Zer01HD.Utilities.UI;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace RhythmBullet.Zer01HD.Game.Screens.Transitions
{
internal class FadeInTransition : IDisposable
{
public readonly Texture2D curtain;
Rectangle curtainSize;
Color color;
private float progR, progG, progB, progA;
private float rR, rG, rB, rA;
private bool recorded;
internal FadeInTransition(GraphicsDevice graphicsDevice, Color startColor, Vector2 dimensions)
{
curtain = new Texture2D(graphicsDevice, 1, 1);
curtain.SetData(new[] { startColor });
curtainSize.Width = (int)dimensions.X;
curtainSize.Height = (int)dimensions.Y;
color = startColor;
}
internal void Fade(SpriteBatch batch, float deltaf)
{
if (progR > 0 || progG > 0 || progB > 0)
{
if (!recorded)
{
rR = (0 - color.R) / 1f;
rG = (0 - color.G) / 1f;
rB = (0 - color.B) / 1f;
rA = (0 - color.A) / 1f;
recorded = true;
}
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;
}
batch.Draw(curtain, curtainSize, color);
}
public void Dispose()
{
curtain.Dispose();
}
}
}