hi,
what is the most efficient way to pick sprites in a sorted manner?
i've got another fake z-depth scenario that does not handle well with a lot of objects, probably due to bad loop management. here is the cap, in a nutshell: i want to create the illusion of skyscrapers by stacking rectangles (floors) onto each other. currently there are sprites for the bottom & a number of sprites for the floors (the bottoms are invisible). the sorting works like this:
1) pick each bottom, one after another, sorted by their y-position
2) pick all floors belonging to that bottom (by comparing a private variable)
3) pick each of these floors, one after another, sorted by their intended height (another private variable)
4) put that floor into position & send him to front
like this, it works mostly correct (few glitches): the top floors are covering the lower floors, and the closer skyscrapers cover the ones further away. but adding more skyscrapers drastically impacts the framerate (my laptop drops <60 with 100 bottoms and ~800 floors). i suspect that the three nested loops are responsible, blowing through ( bottoms * floors(all) * floors(selection)) = 640k iterations each frame.
sooo... any ideas on a more efficient approach? anything i can think of using other objects (arrays?) hits the bottleneck of picking the corresponding sprite after the sorting. any help would be welcome!
(otherwise i'd have to scale down from downtown to suburbia ;))