Drawing a lot of layers sorted by depth

Started by
0 comments, last by agaudreau 15 years, 3 months ago
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 :)
the rug - funpowered.com
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()

This topic is closed to new replies.

Advertisement