Render multiple layers in XNA
Posted
by Charles
on Stack Overflow
See other posts from Stack Overflow
or by Charles
Published on 2010-04-10T21:13:39Z
Indexed on
2010/05/12
0:04 UTC
Read the original article
Hit count: 177
I'm using XNA, and I've run into a little problem. I need to support multiple layers, each with a distinct z order (I call these "viewports"). A picture is worth a thousand words, so here's what it should look like:
There are several things to notice here. Sprites do not render outside of their viewport, as you can see with Sprite B. Also, notice how the viewports are rendered - it's very similar to "layers" in Photoshop. Although Sprite C is has a z order of -1000, C still renders above Sprite A because its viewport's z-order is a greater than A's viewport's z-order.
There's one last detail that I couldn't display very well in the above picture. Each viewport needs to optionally render a color over its region of the screen - you could think of it as a "tinting" affect.
I'm completely at a loss when it comes to doing this the best way in XNA, so I could really use a short snippet of C#/VB.NET code that demonstrates this in action. Any help would be greatly appreciated.
© Stack Overflow or respective owner