Jump to content
  • Advertisement
Sign in to follow this  
The Rug

Drawing a lot of layers sorted by depth

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi everyone I have a 2D renderer where my level is composed of a bunch of "layers". These are basically chunks of renderable stuff, they can contain tiles, prerendered images, animations, whatever. Each layer is an arbitrary size and position within my 2d world, there can be a lot of them, and theyre not all onscreen at once. Each one also has a depth value, which does not change as the game is running. My problem: I'm trying to render them in quickly and in their proper order. My current best idea for a solution is: -Store the layers in a quadtree -As I traverse the tree, add each layer that is onscreen to a buffer -When traversal is finished, sort the layers in the buffer by depth -Render the buffer This means instering/sorting the layers every frame. Though the sorting can probably be done as each layer is inserted into the buffer, using a tree for the buffer. Im just wondering, is there a better way to do this? I'm a bit out of touch with programming these days and I get this sneaking feeling I've missed something... Thanks peeps :)

Share this post


Link to post
Share on other sites
Advertisement
If they are not going to change Z values then its as simple as sorting for z once durring load and then doing a bounds checks every frame to see if you want to render it.

for(each layer)
if(layer is in screenspace)
layer.render()

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!