Sign in to follow this  
GenuineXP

2D Scene Graphs: Applying Transformations AND Depth Sorting?

Recommended Posts

So I have no experience with scene graphs, but I've decided I want to implement one for my 2D engine. I know layers are often used for 2D applications, but they have some limitations and scene graphs seem to have some very useful abilities (for example, they could be useful for game entities composed of many moving, rotating sprites). The problem is, how can a scene graph apply translations, rotations, effects, etc., while also sorting/ordering drawing operations for correct depth? Is this even possible? I've found several useful articles about scene graphs, but they're all in terms of 3D applications (where the actual order in which drawing operations occur doesn't necessarily affect the depth/ordering of objects). My engine uses hardware support (via OpenGL currently), so is there a way I could employ the depth buffer to nullify the effect of the order in which drawing operations are performed? For now, I want to keep things very basic (a graph can apply simple translations and rotations, and that's about it). I've reviewed a few recommended patterns in the GoF's Design Patterns just to be sure I'm on my toes for this. :-) Thanks!

Share this post


Link to post
Share on other sites
You don't necessarily have to draw the sprites while you're traversing the graph. I would do the scene graph step first. Store the result for each sprite in a list with a reference to the sprite the result was for. Sort the list accordingly, then draw. The implementation details are up to you.

If you're using the opengl depth buffer, then it shouldn't matter in which order you are drawing unless you're using transparency or you're somehow using the entire precision range of the depth buffer, in which case you'll have to clear it multiple times per frame, but I find this extremely unlikely for a 2D application.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this