Added better system for beginning sprite batches for easier consistency.
This commit is contained in:
@@ -12,6 +12,12 @@ namespace RecrownedAthenaeum.ScreenSystem
|
||||
/// <param name="screen">The screen to show after the loading screen.</param>
|
||||
public delegate void ShowFirstScreen(Screen screen);
|
||||
|
||||
/// <summary>
|
||||
/// Custom spritebatch begin call.
|
||||
/// </summary>
|
||||
/// <param name="spriteBatch"></param>
|
||||
public delegate void BeginBatch(SpriteBatch spriteBatch);
|
||||
|
||||
/// <summary>
|
||||
/// A manager for screens. Helps with transitions and updating screens as well as resizes.
|
||||
/// </summary>
|
||||
@@ -23,6 +29,12 @@ namespace RecrownedAthenaeum.ScreenSystem
|
||||
/// Called when the first loading screen is done, and needs to show the landing screen.
|
||||
/// </summary>
|
||||
public event ShowFirstScreen ShowFirstScreenEvent;
|
||||
|
||||
/// <summary>
|
||||
/// The function to call that begins the batch.
|
||||
/// </summary>
|
||||
public BeginBatch beginBatchFunc;
|
||||
|
||||
private GraphicsDeviceManager graphics;
|
||||
private Screen previousScreen;
|
||||
private RenderTarget2D previousScreenRenderTarget;
|
||||
@@ -65,13 +77,16 @@ namespace RecrownedAthenaeum.ScreenSystem
|
||||
/// </summary>
|
||||
/// <param name="camera">The camera to be used to perform the correct translations and transformations. Will use default set in <see cref="Configuration"/> if left null.</param>
|
||||
/// <param name="graphicsDeviceManager">The graphics device manager to be used. Will use default set in <see cref="Configuration"/> if left null.</param>
|
||||
public ScreenManager(Camera2D camera = null, GraphicsDeviceManager graphicsDeviceManager = null)
|
||||
/// <param name="beginBatchFunction">The function to call to begin a batch to be used generally. Will use the built-in one in screen manager if not provided.</param>
|
||||
public ScreenManager(Camera2D camera = null, GraphicsDeviceManager graphicsDeviceManager = null, BeginBatch beginBatchFunction = null)
|
||||
{
|
||||
if (beginBatchFunction == null) beginBatchFunction = BasicBeginBatch;
|
||||
if (camera == null) camera = Configuration.Camera2D;
|
||||
if (graphicsDeviceManager == null) graphicsDeviceManager = Configuration.GraphicsDeviceManager;
|
||||
|
||||
graphics = graphicsDeviceManager ?? throw new ArgumentNullException("Graphics device manager argument cannot be null if setup's graphics device manager is also null.");
|
||||
this.camera = camera ?? throw new ArgumentNullException("2d camera argument cannot be null if setup's 2d camera is also null.");
|
||||
beginBatchFunc = beginBatchFunction;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -129,13 +144,13 @@ namespace RecrownedAthenaeum.ScreenSystem
|
||||
{
|
||||
graphics.GraphicsDevice.SetRenderTarget(previousScreenRenderTarget);
|
||||
graphics.GraphicsDevice.Clear(previousScreen.BackgroundColor);
|
||||
spriteBatch.Begin(effect: camera.BasicEffect);
|
||||
beginBatchFunc(spriteBatch);
|
||||
previousScreen.Draw(spriteBatch);
|
||||
spriteBatch.End();
|
||||
graphics.GraphicsDevice.SetRenderTarget(null);
|
||||
Screen.UpdatePreviousScreenFrame(previousScreenRenderTarget);
|
||||
}
|
||||
spriteBatch.Begin(effect: camera.BasicEffect);
|
||||
beginBatchFunc(spriteBatch);
|
||||
Screen.Draw(spriteBatch);
|
||||
spriteBatch.End();
|
||||
}
|
||||
@@ -199,5 +214,10 @@ namespace RecrownedAthenaeum.ScreenSystem
|
||||
{
|
||||
Dispose(false);
|
||||
}
|
||||
|
||||
private void BasicBeginBatch(SpriteBatch spriteBatch)
|
||||
{
|
||||
spriteBatch.Begin(effect: camera.BasicEffect, blendState: BlendState.NonPremultiplied);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user