Heh, usually I'm the one answering questions in this forum, but I've got a question that's keeping me from making a project (hopefully the first I'll have made in months). Does anyone know how to organize several sprites layer-wise based on a variable?
Say I have three sprites, each with a variable "Z position". The one with the lowest "Z Position" should be in the front, the one with the highest "Z Position" should be in the back, and obviously the middle one in the middle.
But get this. Say their Z Positions change, and the middle one gets a lower Z than the front one. Now they have to switch around on the layers, and the back one has to stay back. I need this to compute and render within one frame.
It would also really help if you could make it flexible (easy to add and subtract the number of sprites switching themselves around) but if you can't do that that's ok.
I've already got a rough script, but it doesn't work very well and does not render within one frame.
Thanks in advance!
Last edited by Kileymeister (2011-09-30 19:22:58)
Offline
Well what you could do is have each layer go to the front everytime and then go back your specified layers...I'll work on an example if you want it.
Offline
Hm, not a bad idea. I'd been toying with the idea of setting each one to the front in order (starting with the furthest back), but this sounds like it would work better.
I don't really need an example, I think I've got this. Thanks!
Last edited by Kileymeister (2011-10-01 15:07:39)
Offline
You don't need "go back () layers" really, you could just order when which sprite "goes to front". I'm not sure if this would be faster though.
Offline
Multiple testing has revealed that Atomic_Bawm's method will not be very flexible, as each sprite's Z value must be compared to each other sprite's Z value. Simply writing "go to front > go back Z position layers" produces inaccurate results. This method does work, and will be my fallback method, but I'll search for something a bit more flexible, as I plan to use many sprites with this method.
Maybe I'm not quite doing it the way you were suggesting, Bawm. If you could write your own example that'd be a big help.
Last edited by Kileymeister (2011-10-01 15:11:17)
Offline
Well no, I hadn't considered what you had wanted...depending on how you would want it layered and what the x,y,z maxes are, you could do some combination of multiplying them together so that 2 sprites on the same z can still overlap each other in the order you want.
Offline
Well, there only only two blocks that affect the layer of a sprite. Go To Front, and Go Back () layers. Seems to me that the two options are:
a) make each sprite "go to front" in order of their depth.
or
b) make them all go to front and then go back their depth.
Offline