Sign in to follow this  
ptchaos

Best way to use zIndex

Recommended Posts

ptchaos    135

Greetings,

 

I have a list of objects that have a property zIndex, which indicates the order the objects are processed (updated/draw).

 

Whats the best way to process them in the correct order? Sort the vector each time I push a new object? Use another kind of container?

 

Think about operative system windows. Usual they are showed in the order they are opened (with some exceptions ofc). But when you click on one in the back, it activates and passes to the front. Does it remove from the list and pushes again so its the last to be drawn?

 

Think in a top-down game. You have the ground tiles, then ground objects, then flying objects. Do you have separated lists for each layer?

 

It probably depends on the use, but whats the usual approach to this?

 

 

Thanks,

 

chaos

Share this post


Link to post
Share on other sites
SiCrane    11839
I would say there is probably no usual way to do this. Depending on application, you may stick objects into a vector and sort on every insertion, stuff objects into an sorted associative container like a map, generate a new sorted list every time you render, ignore z order for objects and depend on the renderer to sort faces of the objects as part of the render and so on. A window manager has very different requirements for z order than a game with highly dynamic objects and view points.

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