improved transition system with usage of target rendering

This commit is contained in:
Harrison Deng 2018-11-03 01:08:39 -05:00
parent 44b2c74ff5
commit 042fba4249
4 changed files with 69 additions and 27 deletions

View File

@ -62,13 +62,17 @@ namespace RhythmBullet
{
if (currentScreen != null)
{
previousScreen = value;
if (value.GetType() != typeof(MainScreen))
{
previousScreen = value;
}
Screen.Hide();
}
currentScreen = value;
currentScreen.ScreenSize.Width = graphics.PreferredBackBufferWidth;
currentScreen.ScreenSize.Height = graphics.PreferredBackBufferHeight;
if (!Screen.Initiated)
{
Screen.Initiate(new Rectangle(0, 0, graphics.PreferredBackBufferWidth, graphics.PreferredBackBufferHeight), graphics.GraphicsDevice);
}
Screen.Show();
}
}
@ -128,12 +132,26 @@ namespace RhythmBullet
switch (Screen.State)
{
case ScreenState.EnterTransition:
Screen.EnteringTransition(gameTime.ElapsedGameTime.TotalSeconds, Assets.Done, ref BackgroundColor);
if (previousScreen != null && previousScreen.UseRenderTargetForExitTransition)
{
graphics.GraphicsDevice.SetRenderTarget(previousScreen.RenderTarget);
previousScreen.ExitingTransition(gameTime.ElapsedGameTime.TotalSeconds, Assets.Done, ref BackgroundColor);
previousScreen.Draw(spriteBatch);
graphics.GraphicsDevice.SetRenderTarget(null);
}
Screen.EnteringTransition(gameTime.ElapsedGameTime.TotalSeconds, Assets.Done, ref BackgroundColor, previousScreen?.RenderTarget);
break;
case ScreenState.ExitTransition:
if (Screen.ExitingTransition(gameTime.ElapsedGameTime.TotalSeconds, Assets.Done, ref BackgroundColor))
if (Screen.UseRenderTargetForExitTransition || Screen.ExitingTransition(gameTime.ElapsedGameTime.TotalSeconds, Assets.Done, ref BackgroundColor))
{
Screen = previousScreen != null ? previousScreen : new MainScreen(graphics.GraphicsDevice, BackgroundColor, Assets);
if (Screen.NextScreen != null)
{
Screen = Screen.NextScreen;
}
else
{
Screen = previousScreen != null ? previousScreen : new MainScreen(graphics.GraphicsDevice, BackgroundColor, Assets);
}
}
break;
case ScreenState.Normal:

View File

@ -36,10 +36,10 @@ namespace RhythmBullet.Zer01HD.Game.Screens
base.Draw(spriteBatch);
}
public override void EnteringTransition(double delta, bool assetsLoaded, ref Color backgroundColor)
public override void EnteringTransition(double delta, bool assetsLoaded, ref Color backgroundColor, RenderTarget2D previousScreenExitFrame)
{
fadeInTransition.Fade((float)delta);
base.EnteringTransition(delta, assetsLoaded, ref backgroundColor);
base.EnteringTransition(delta, assetsLoaded, ref backgroundColor, previousScreenExitFrame);
}
}
}

View File

@ -42,7 +42,7 @@ namespace RhythmBullet.Zer01HD.Game
base.Update(gameTime);
}
public override void EnteringTransition(double delta, bool assetsLoaded, ref Color BGColor)
public override void EnteringTransition(double delta, bool assetsLoaded, ref Color BGColor, RenderTarget2D previousScreenExitFrame)
{
float deltaf = (float)delta;
if (rotate)
@ -73,7 +73,7 @@ namespace RhythmBullet.Zer01HD.Game
else
{
DoneEnterTransition();
StartExitTransition();
StartExitTransition(true);
}
}
}

View File

@ -12,13 +12,19 @@ namespace RhythmBullet.Zer01HD.Utilities.UI
public class Screen
{
public Rectangle ScreenSize;
ScreenState state;
public bool UseRenderTargetForExitTransition;
private GraphicsDevice GraphicsDevice;
public Screen(bool useEnterTransition = false)
{
state = useEnterTransition ? ScreenState.EnterTransition : ScreenState.Normal;
State = useEnterTransition ? ScreenState.EnterTransition : ScreenState.Normal;
}
public void Initiate(Rectangle screenSize, GraphicsDevice graphicsDevice)
{
Initiated = true;
this.ScreenSize = screenSize;
this.GraphicsDevice = graphicsDevice;
RenderTarget = new RenderTarget2D(graphicsDevice, ScreenSize.Width, ScreenSize.Height);
}
public virtual void Update(GameTime gameTime)
@ -31,7 +37,7 @@ namespace RhythmBullet.Zer01HD.Utilities.UI
}
public virtual void EnteringTransition(double delta, bool assetsLoaded, ref Color backgroundColor)
public virtual void EnteringTransition(double delta, bool assetsLoaded, ref Color backgroundColor, RenderTarget2D previousScreenExitFrame)
{
}
@ -56,23 +62,41 @@ namespace RhythmBullet.Zer01HD.Utilities.UI
}
public ScreenState State
{
get
{
return state;
}
}
public ScreenState State { get; private set; }
public void DoneEnterTransition()
{
state = ScreenState.Normal;
State = ScreenState.Normal;
}
public void StartExitTransition()
public void StartExitTransition(bool UseRenderTargetForExitTransition = false)
{
state = ScreenState.ExitTransition;
this.UseRenderTargetForExitTransition = UseRenderTargetForExitTransition;
State = ScreenState.ExitTransition;
}
public Screen NextScreen
{
get; protected set;
}
public Rectangle ScreenSize
{
get;
protected set;
//Remember to init in init func
}
public RenderTarget2D RenderTarget
{
get;
private set;
}
public bool Initiated
{
get;
private set;
}
}
}