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

#1 2008-01-06 10:40:18

Paddle2See
Scratch Team
Registered: 2007-10-27
Posts: 1000+

How many Layers does Scratch have?

I'm working on a project that tries to show Foreground/Background using layers.  I would like to know a couple of things:

1.  How many layers does Scratch recognize?

2. Once you set the layer of a Sprite, what actions can cause it to change?  It seems that when a Sprite is selected in development mode, it is brought to Front.  Are there other actions (Besides Go to Front and Go Back x Layers) that cause a change of layer? 

Thanks for your assistance.


http://i39.tinypic.com/2nav6o7.gif

Offline

 

#2 2008-01-06 13:32:43

kevin_karplus
Scratcher
Registered: 2007-04-27
Posts: 1000+

Re: How many Layers does Scratch have?

I believe that scratch has as many layers as it has things to display—that is that there is one master list of all displayable objects and the "layer" is just the position on the list.
You have found the only 2 supported actions.

My son and I worked out a semantics for a Z dimension that would be compatible with the current system: http://scratch.mit.edu/forums/viewtopic.php?pid=10766#p10766
but I don't know if the Scratch team is interested in going from 2D to 2.5D.

Offline

 

#3 2008-01-06 13:57:14

Paddle2See
Scratch Team
Registered: 2007-10-27
Posts: 1000+

Re: How many Layers does Scratch have?

When you say "displayable objects", does that include hidden sprites?  Does the action of Hide/Show change the position in the display list?  In other words, if object B is behind A and A then goes through a Hide/Show cycle, is B still behind A when it reappears?  I can do some experiments to try and figure this out, but if you have already done them or have information from the Scratch team, it could save a lot of time.

I think 2.5D would be a great addition to Scratch.  The current system is quite cumbersome.  At least, it's giving me pains.


http://i39.tinypic.com/2nav6o7.gif

Offline

 

#4 2008-01-06 19:05:00

kevin_karplus
Scratcher
Registered: 2007-04-27
Posts: 1000+

Re: How many Layers does Scratch have?

I have not checked whether hide/show changes layers.  It is an easy test.

I made 2 sprites that overlapped.
One had
when down arrow key pressed
     hide
The other had
  when up arrow key pressed
      hide
Both had
  when space key pressed
      show

Playing with the arrow keys indicated no change in level when hiding and showing.
The same sprite was always on top.

Offline

 

#5 2008-01-06 21:01:50

Paddle2See
Scratch Team
Registered: 2007-10-27
Posts: 1000+

Re: How many Layers does Scratch have?

Thanks!


http://i39.tinypic.com/2nav6o7.gif

Offline

 

#6 2008-01-06 23:41:29

EdnaC
Scratcher
Registered: 2007-08-28
Posts: 100+

Re: How many Layers does Scratch have?

The go to top command, and go back (so many) is pretty confusing.  The last sprite told to "go to front" ends up in front, so the "stack" is ever-changing if you continue to command different sprites to "go to front".  It would be nice to have a more ordered way to control this, but the goal is to keep things simple, so implementing a more structured order for who's on top could be beyond where the Scratch team wants to go.

I've set sprite layers up by using wait statements (top sprite waits the longest) in the "Green flag" of each to get the order right, which is OK to initalize a project.  I suppose that you could do a cascade of broadcasts if you need control of the layer order during runtime (seems pretty messy).

-Mr Ed

Offline

 

#7 2008-01-07 03:32:54

Paddle2See
Scratch Team
Registered: 2007-10-27
Posts: 1000+

Re: How many Layers does Scratch have?

Yes, it does get pretty messy.  That is the problem, there is no absolute order.  But now that I've got a slightly better idea of what is happening, maybe I can come up with something workable.

The project I'm working on sounds simple enough:  There is a cat in a field with a large rock.  I want the cat to be able to walk behind the rock when it is at a greater Y value than the base of the rock and in front of the rock when it is at a Y value less than that of the base of the rock.  It gets pretty messy though when you look at oblique traveling paths that intersect with the base of the rock; when traveling from below, you want the rock to stay in the background until the entire cat is over it.  When traveling from above, I want the rock to stay in the foreground until the feet of the cat travel lower than the rock (the cat needs to be able to "hide").  I have a messy algorithm that works fairly well under most conditions now but it does not scale well with additional objects in the space and I feel there should be a cleaner solution.

Last edited by Paddle2See (2008-01-07 03:34:13)


http://i39.tinypic.com/2nav6o7.gif

Offline

 

#8 2008-01-07 11:42:23

kevin_karplus
Scratcher
Registered: 2007-04-27
Posts: 1000+

Re: How many Layers does Scratch have?

Mr. Ed, have you read the suggestion at
http://scratch.mit.edu/forums/viewtopic.php?pid=10766#p10766
What do you think of that way of handling layers? 
It was the simplest we could come up with that would retain backward compatibility with existing Scratch programs.

Offline

 

#9 2008-01-07 12:21:12

EdnaC
Scratcher
Registered: 2007-08-28
Posts: 100+

Re: How many Layers does Scratch have?

That seems very reasonable to me.  Leaving the "z" out of the description and just calling the new value "layer number" would probably clear the confusion up (z seemed to get people thinking of 3d).

Some layer list must already exist within Scratch, so it seems like the implementation wouldn't be too hard.  I haven't bothered much with this recently, but it seemed to me that what must be going on is something like:

Each new sprite adds an unseen "layer" to the project (perhaps each new sprite goes to the "most" distant layer?).  So Sprite 1 is on layer zero (front), Sprite2 is on layer 1, etc. 

Telling Sprite3 to go to the front would bump S1 and S2 back. 

Telling Sprite3 to go back one layer would put it between S1 and S2 (maybe?).  This gets really messy when a lot of sprites are involved and you want to control who is in front of who.

Offline

 

#10 2008-01-07 12:58:49

kevin_karplus
Scratcher
Registered: 2007-04-27
Posts: 1000+

Re: How many Layers does Scratch have?

The advantage of "z" rather than layer number is the ability to have non-integer "z".
If you have two sprites at different depths, you could put a new one in with

set depth to (sprite1's depth + sprite2's depth)/2

I like the word "depth" better than "layer number" or "z", since it more clearly communicates that 0 is the front and infinity is the background.

Offline

 

Board footer