I've been working on a 2D tile-based game. The whole thing is created in C#, XNA 3.1 and uses spritebatch to draw everything. Lately I've been trying to add a bit of depth to the game with some basic lighting technique that blends images over the current map. This seemed to work nicely at first, but then I realized that after the game has been running for a few minutes the FPS drops by half or more, and begins to run sluggishly. Also note, the only time the FPS drops is when the lighting is on, and when i turn the lighting off... the FPS jumps right back up to 60.
I've attatched a screenshot that shows what the lighting looks like, and what it looks like without. I'm at a loss. I can't figure out why it begins to run sluggishly... Any help/suggestions would be appreciated.
DrawToRenderTarget...()
{
this.GraphicsDevice.SetRenderTarget(0, this.region.lightMap);
//clear to some small ambient light
this.GraphicsDevice.Clear(this.region.ambience);
//where Alpha is 0, nothing will be written
this.spriteBatch.Begin(SpriteBlendMode.AlphaBlend, SpriteSortMode.Immediate, SaveStateMode.SaveState);
this.spriteBatch.GraphicsDevice.RenderState.DestinationBlend = Blend.One;
this.spriteBatch.GraphicsDevice.RenderState.SourceBlend = Blend.DestinationAlpha;
this.spriteBatch.GraphicsDevice.RenderState.BlendFunction = BlendFunction.Add;
this.spriteBatch.GraphicsDevice.RenderState.SeparateAlphaBlendEnabled = true;
foreach (LightSource light in this.region.regionLightSourceInstances)
{
light.Draw(this.spriteBatch);
}
this.spriteBatch.End();
this.GraphicsDevice.SetRenderTarget(0, null);
}
Thank you.