ScreenEffectManager now passes off a "service-located" SpriteBatch object to it's effects

This commit is contained in:
Gered 2013-08-24 16:29:56 -04:00
parent db4802beda
commit 2547677649
5 changed files with 14 additions and 9 deletions

View file

@ -16,7 +16,7 @@ namespace Blarg.GameFramework.Graphics.ScreenEffects
Alpha = DefaultDimAlpha;
}
public override void OnRender(float delta)
public override void OnRender(float delta, SpriteBatch spriteBatch)
{
int width = Framework.GraphicsDevice.ViewContext.ViewportWidth;
int height = Framework.GraphicsDevice.ViewContext.ViewportHeight;
@ -25,7 +25,7 @@ namespace Blarg.GameFramework.Graphics.ScreenEffects
var color = Color;
color.A = Alpha;
//Platform.SpriteBatch.Render(texture, 0, 0, width, height, ref color);
spriteBatch.Render(texture, 0, 0, width, height, ref color);
}
}
}

View file

@ -42,7 +42,7 @@ namespace Blarg.GameFramework.Graphics.ScreenEffects
_fadeToAlpha = toAlpha;
}
public override void OnRender(float delta)
public override void OnRender(float delta, SpriteBatch spriteBatch)
{
int width = Framework.GraphicsDevice.ViewContext.ViewportWidth;
int height = Framework.GraphicsDevice.ViewContext.ViewportHeight;
@ -50,7 +50,7 @@ namespace Blarg.GameFramework.Graphics.ScreenEffects
var texture = Framework.GraphicsDevice.GetSolidColorTexture(Color.White);
_color.A = _alpha;
//Platform.SpriteBatch.Render(texture, 0, 0, width, height, ref _color);
spriteBatch.Render(texture, 0, 0, width, height, ref _color);
}
public override void OnUpdate(float delta)

View file

@ -24,7 +24,7 @@ namespace Blarg.GameFramework.Graphics.ScreenEffects
Color = Color.White;
}
public override void OnRender(float delta)
public override void OnRender(float delta, SpriteBatch spriteBatch)
{
int width = Framework.GraphicsDevice.ViewContext.ViewportWidth;
int height = Framework.GraphicsDevice.ViewContext.ViewportHeight;
@ -33,7 +33,7 @@ namespace Blarg.GameFramework.Graphics.ScreenEffects
var color = Color;
color.A = _alpha;
//Platform.SpriteBatch.Render(texture, 0, 0, width, height, ref color);
spriteBatch.Render(texture, 0, 0, width, height, ref color);
}
public override void OnUpdate(float delta)

View file

@ -44,7 +44,7 @@ namespace Blarg.GameFramework.Graphics.ScreenEffects
{
}
public virtual void OnRender(float delta)
public virtual void OnRender(float delta, SpriteBatch spriteBatch)
{
}

View file

@ -8,12 +8,17 @@ namespace Blarg.GameFramework.Graphics.ScreenEffects
LinkedList<EffectInfo> _effects;
int _numLocalEffects;
int _numGlobalEffects;
SpriteBatch _spriteBatch;
public ScreenEffectManager()
{
_effects = new LinkedList<EffectInfo>();
_numLocalEffects = 0;
_numGlobalEffects = 0;
_spriteBatch = Framework.Services.Get<SpriteBatch>();
if (_spriteBatch == null)
throw new InvalidOperationException("No SpriteBatch object registered with the service locator.");
}
#region Get / Add / Remove
@ -133,7 +138,7 @@ namespace Blarg.GameFramework.Graphics.ScreenEffects
for (var node = _effects.First; node != null; node = node.Next)
{
if (node.Value.IsLocal)
node.Value.Effect.OnRender(delta);
node.Value.Effect.OnRender(delta, _spriteBatch);
}
}
@ -145,7 +150,7 @@ namespace Blarg.GameFramework.Graphics.ScreenEffects
for (var node = _effects.First; node != null; node = node.Next)
{
if (!node.Value.IsLocal)
node.Value.Effect.OnRender(delta);
node.Value.Effect.OnRender(delta, _spriteBatch);
}
}