Discuss Scratch
- Discussion Forums
- » Help with Scripts
- » Layering problem, any solutions?
- kingliam3
-
Scratcher
45 posts
Layering problem, any solutions?
I am creating my next big game and just first getting over my first major problem. I now have another…
My new game is way more complex than any of my previous ones, my scenes consists of multiple layers of sprites (Around 20 layers)
these layers keep becoming out of order and the (Go to Front) / (Go back _ ) scripts don't seems to work correctly.
Does anyone have a reliable, easy to implement solution that I could use to get me back focusing on the rest of my game
Thanks!
My new game is way more complex than any of my previous ones, my scenes consists of multiple layers of sprites (Around 20 layers)
these layers keep becoming out of order and the (Go to Front) / (Go back _ ) scripts don't seems to work correctly.
Does anyone have a reliable, easy to implement solution that I could use to get me back focusing on the rest of my game

Thanks!
Last edited by kingliam3 (Oct. 17, 2013 15:55:45)
- PH-zero
-
Scratcher
100+ posts
Layering problem, any solutions?
Mhh… i need more information.
What is a layer? Do you mean you have 20 Sprites?
Or real “Layers” like in most painting-programs, where several sprites can be
on one layer?
What is a layer? Do you mean you have 20 Sprites?
Or real “Layers” like in most painting-programs, where several sprites can be
on one layer?
- DadOfMrLog
-
Scratcher
1000+ posts
Layering problem, any solutions?
Sprite layering in Scratch is full of great adventures for the unwary… 
There are several things you need to be clear about in order to control the layering of sprites using “go to front” and “go back _” - here are some key points:
1. Every object you ever show on the screen takes up a layer. That includes each sprite, each existing clone of each sprite, each variable you ever show (i.e. pretty much every one you ever create), each reporter you ever show (e.g. size, direction, x position, mouse x…)
2. Even if you hide a sprite/clone/variable/reporter, it still takes up a layer, so you need to deal with it when you “go back” other sprites.
3. Every time you “show” a variable (or a reporter that was previously hidden, or never shown before) it comes to the top layer.
4. You can put a negative number into “go back _” and then it will go forward instead (can be handy occasionally…)
So, with all that said, my own experience with layering is that you usually want to avoid having to think about anything that's hidden (sprites/clones/variable/reporters).
That means a few of things:
1. You should keep track of which sprites you have showing and which hidden, and ensure you never change the layer of anything that is hidden.
2. When you hide a sprite, also move it back loads of layers. This ensures it is out of the way of any calculations of how many layers back you want to move other things (and remember not to count that sprite when working out how many layers to move back for other sprites).
3. The most reliable way to get the right layer for some sprite/clone at some specific point in your scripts is to do it in two steps. First, go to front, second go back however far you need to. You can put these two into a custom block (“move to layer N”, or something) with screen refresh off to ensure you don't see flickering as it gets moved to front, then backward.
Hope that all proves useful!

There are several things you need to be clear about in order to control the layering of sprites using “go to front” and “go back _” - here are some key points:
1. Every object you ever show on the screen takes up a layer. That includes each sprite, each existing clone of each sprite, each variable you ever show (i.e. pretty much every one you ever create), each reporter you ever show (e.g. size, direction, x position, mouse x…)
2. Even if you hide a sprite/clone/variable/reporter, it still takes up a layer, so you need to deal with it when you “go back” other sprites.
3. Every time you “show” a variable (or a reporter that was previously hidden, or never shown before) it comes to the top layer.
4. You can put a negative number into “go back _” and then it will go forward instead (can be handy occasionally…)
So, with all that said, my own experience with layering is that you usually want to avoid having to think about anything that's hidden (sprites/clones/variable/reporters).
That means a few of things:
1. You should keep track of which sprites you have showing and which hidden, and ensure you never change the layer of anything that is hidden.
2. When you hide a sprite, also move it back loads of layers. This ensures it is out of the way of any calculations of how many layers back you want to move other things (and remember not to count that sprite when working out how many layers to move back for other sprites).
3. The most reliable way to get the right layer for some sprite/clone at some specific point in your scripts is to do it in two steps. First, go to front, second go back however far you need to. You can put these two into a custom block (“move to layer N”, or something) with screen refresh off to ensure you don't see flickering as it gets moved to front, then backward.
Hope that all proves useful!
- Discussion Forums
- » Help with Scripts
-
» Layering problem, any solutions?



