Best way to use zIndex

Started by
0 comments, last by SiCrane 11 years, 1 month ago

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

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

This topic is closed to new replies.

Advertisement