improved transition system, target rendering portion tested with loading to main screen.

This commit is contained in:
2018-11-04 00:01:17 -05:00
parent 042fba4249
commit 99a8531b47
9 changed files with 329 additions and 225 deletions

View File

@@ -4,8 +4,10 @@ using RhythmBullet.Zer01HD.Game.Screens.Transitions;
using RhythmBullet.Zer01HD.UI;
using RhythmBullet.Zer01HD.Utilities.ContentSystem;
using RhythmBullet.Zer01HD.Utilities.UI;
using RhythmBullet.Zer01HD.Utilities.UI.ScreenSystem;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
@@ -15,31 +17,24 @@ namespace RhythmBullet.Zer01HD.Game.Screens
class MainScreen : Screen
{
Texture2D background;
FadeInTransition fadeInTransition;
public MainScreen(GraphicsDevice graphicsDevice, Color transitionFromColor, ContentSystem assets) : base(true)
public MainScreen(GraphicsDevice graphicsDevice, ContentSystem assets) : base(true)
{
fadeInTransition = new FadeInTransition(graphicsDevice, transitionFromColor);
FadeAwayTransition fadeAwayTransition = new FadeAwayTransition();
Transitions.Add(fadeAwayTransition);
graphicsDevice.Clear(Color.White);
background = assets.Get<Texture2D>("backgrounds/mainBG");
}
}
public override void Show()
{
fadeInTransition.Init(ScreenSize);
base.Show();
}
public override void Draw(SpriteBatch spriteBatch)
{
spriteBatch.Draw(background, ScreenSize, Color.White);
fadeInTransition.Draw(spriteBatch);
base.Draw(spriteBatch);
}
public override void EnteringTransition(double delta, bool assetsLoaded, ref Color backgroundColor, RenderTarget2D previousScreenExitFrame)
{
fadeInTransition.Fade((float)delta);
base.EnteringTransition(delta, assetsLoaded, ref backgroundColor, previousScreenExitFrame);
}
}
}

View File

@@ -1,6 +1,7 @@
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using RhythmBullet.Zer01HD.Utilities.UI;
using RhythmBullet.Zer01HD.Utilities.UI.ScreenSystem;
using System;
using System.Collections.Generic;
using System.Diagnostics;
@@ -10,29 +11,22 @@ using System.Threading.Tasks;
namespace RhythmBullet.Zer01HD.Game.Screens.Transitions
{
internal class FadeInTransition : IDisposable
internal class FadeAwayTransition : IDisposable, ITransition
{
private const float RATE = 0.3f;
public readonly Texture2D curtain;
private const float TIME_REQUIRED = 2f;
public 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 });
private float rR, rG, rB, rA;
color = startColor;
}
internal void Init(Rectangle dimensions)
internal FadeAwayTransition()
{
curtainSize = dimensions;
rR = (0 - color.R) / RATE;
rG = (0 - color.G) / RATE;
rB = (0 - color.B) / RATE;
rA = (0 - color.A) / RATE;
color = Color.White;
rR = (0 - 254) / TIME_REQUIRED;
rG = (0 - 254) / TIME_REQUIRED;
rB = (0 - 254) / TIME_REQUIRED;
rA = (0 - 254) / TIME_REQUIRED;
progA = color.A;
progR = color.R;
@@ -40,7 +34,12 @@ namespace RhythmBullet.Zer01HD.Game.Screens.Transitions
progB = color.B;
}
internal bool Fade(float deltaf)
public void InitiateTransition(Rectangle dimensions)
{
curtainSize = dimensions;
}
private bool Fade(float deltaf)
{
if (progR > 0 || progG > 0 || progB > 0)
{
@@ -58,20 +57,32 @@ namespace RhythmBullet.Zer01HD.Game.Screens.Transitions
color.A = (byte)progA;
return false;
}
return false;
return true;
}
internal void Draw(SpriteBatch batch)
public void DrawTransition(SpriteBatch batch)
{
if (curtain != null)
{
batch.Draw(curtain, curtainSize, color);
}
batch.Draw(curtain, curtainSize, color);
}
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;
}
}
}