I don't quite understand how to handle ZBuffering for different screens in my program. I have a screenControllers
class that calls a Draw method for each of my active Screen
classes. The spriteBatch.Begin
and spriteBatch.End
calls are made in the screenController
's Draw. The Screen
's Draw just has a spriteBatch.Draw
statement for each of the textures being drawn. I understand that I can specify depth when calling the
public void Draw (
Texture2D texture,
Rectangle destinationRectangle,
Nullable<Rectangle> sourceRectangle,
Color color,
float rotation,
Vector2 origin,
SpriteEffects effects,
float layerDepth
)
method for spriteBatch
.
But say I open one screen with textures at some given depth. Then, the second screen I open should have other textures at the same depth values as the previous but drawn in order on TOP of the previous screen. I doubt I will need this functionality because the second screen I open will probably be an options screen on top of my scene window with everything in front or it may be a portion of an interface that is not on top of the scene window but to the side. I am just wondering if this layered functionality for multiple screens can be implemented in XNA?
If you use different SpriteBatch
to manage them I don't think you will have this kind of problem.
If you use the same SpriteBatch
you could use a scaleFactor
and an offsetValue
to manage the layerDepth
value of your Draw
s, in order to create different invervals for every sceen's screenDepth
parameter.
I mean that if you have 2 screen the first's textures are drawn in the [0, 0.5)
interval, the second one in [0.5, 1)
. If you have 3 of them the interval will be every 0.33 and so on...
The scaleFactor
will be 1 / numberOfScreens
of course.