[SOLVED] Not able to get the Tiled above layer as transparent using RenderTarget

My question is how can I use one (or more) Render Targets along with SpriteBatch to draw my maps, but also use SpriteBatch to draw my character and NPCs in between the layers (ground and above).

I switched to using a render target (as advised in other threads) since I was getting warped/distorted pixels. So, that is now fixed, but I’m just having the layer depth problem.

If I set the render target, then render the map, and then use spritebatch to draw the map with all layers included, it looks great on screen, but then next I draw my character/player and he walks on top of the “above” layer stuff. So, that doesn’t work.

I tried using render targets to render each map layer separating so that I could draw the ground layer, then set target back to null and draw map, then draw characters, etc, then set render target again and draw last “above” layer. The problem with this approach is that all of the areas in the above layer that should be transparent are drawn black and basically wipe everything else out.

Also, my map itself should be good because if I draw the map and charcters/NPC with SpriteBatch alone, then everything is drawn correctly and works great (other than the warped pixels).

Any ideas? I’m sure I am missing something.


Ok, having read dozens of threads from various forums about this problem I found something that fixed my issue. There is a preserve contents argument that needs to be set in the game constructor. I’ve also read that this is not the best solution for performance, but for now it’s meeting my needs and I’ll re-address later if it becomes an issue. Here is the code I added and a few links to where this is discussed in case it helps someone else…

_graphics.PreparingDeviceSettings += (object s, PreparingDeviceSettingsEventArgs args) =>
            args.GraphicsDeviceInformation.PresentationParameters.RenderTargetUsage = RenderTargetUsage.PreserveContents;