This is a read-only archive of the old Scratch 1.x Forums.
Try searching the current Scratch discussion forums.

#1 2011-09-30 19:17:41

Kileymeister
Scratcher
Registered: 2008-04-17
Posts: 1000+

Realtime Layering

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)


I'm back, and showcasing two new* projects!  Click left or right on the image below to see!
http://img109.imageshack.us/img109/7905/part1l.pnghttp://img859.imageshack.us/img859/6417/part2bf.png

Offline

 

#2 2011-09-30 20:14:43

AtomicBawm3
Scratcher
Registered: 2009-06-27
Posts: 1000+

Re: Realtime Layering

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.


http://i50.tinypic.com/j0yw0p.jpg

Offline

 

#3 2011-09-30 20:18:37

Kileymeister
Scratcher
Registered: 2008-04-17
Posts: 1000+

Re: Realtime Layering

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)


I'm back, and showcasing two new* projects!  Click left or right on the image below to see!
http://img109.imageshack.us/img109/7905/part1l.pnghttp://img859.imageshack.us/img859/6417/part2bf.png

Offline

 

#4 2011-09-30 22:19:38

MoreGamesNow
Scratcher
Registered: 2009-10-12
Posts: 1000+

Re: Realtime Layering

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.


http://images2.layoutsparks.com/1/218929/rubiks-cube-animated-rotating.gif
"Cogito ergo sum" --  I think, therefore I am

Offline

 

#5 2011-10-01 15:08:06

Kileymeister
Scratcher
Registered: 2008-04-17
Posts: 1000+

Re: Realtime Layering

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)


I'm back, and showcasing two new* projects!  Click left or right on the image below to see!
http://img109.imageshack.us/img109/7905/part1l.pnghttp://img859.imageshack.us/img859/6417/part2bf.png

Offline

 

#6 2011-10-01 15:50:08

AtomicBawm3
Scratcher
Registered: 2009-06-27
Posts: 1000+

Re: Realtime Layering

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.


http://i50.tinypic.com/j0yw0p.jpg

Offline

 

#7 2011-10-01 18:31:23

MoreGamesNow
Scratcher
Registered: 2009-10-12
Posts: 1000+

Re: Realtime Layering

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.


http://images2.layoutsparks.com/1/218929/rubiks-cube-animated-rotating.gif
"Cogito ergo sum" --  I think, therefore I am

Offline

 

Board footer