# 2D Scene Graphs: Applying Transformations AND Depth Sorting?

This topic is 4191 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## 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 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.

1. 1
2. 2
3. 3
Rutin
17
4. 4
5. 5
JoeJ
13

• 9
• 14
• 10
• 25
• 9
• ### Forum Statistics

• Total Topics
632645
• Total Posts
3007628
• ### Who's Online (See full list)

There are no registered users currently online

×