Sign in to follow this  

Drawing a lot of layers sorted by depth

This topic is 3288 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
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

This topic is 3288 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.

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