ScratchData LogoScratchData
Back to -_staray_-'s profile

Gobo Depth Sorting

-_-_staray_-•Created February 6, 2021
Gobo Depth Sorting
1
1
5 views
View on Scratch

Instructions

** Overview ** When you have a lot of sprites, it can be difficult to get them in the right order. This is never more evident when trying to create a depth effect with many sprites. In my 100,000 followers project I had just this problem, and so this project was born! (More tutorials on YouTube - Search up griffpatch) ** The Problem ** Each sprite (clone) has a depth position (just like its x & y position) called 'z'.The problem then is re-order all the sprites such that the sprites with a smaller 'z' value are always in front of sprites with a larger 'z' value. ** How does this project solve it ** When you "Broadcast", each sprite/clone receives the broadcast message and runs its script. however, they do not all run at the same time. No they always run in order, one after the other. The first one to run is the one that is in front of all the others, and they run from front to back, one after the other. Note that this is in the order the sprites were when the broadcast block is run. 1) The front sprite runs its order script first (from this broadcast). It adds its z value to a list (defined globally for all sprites). 2) The second sprite runs its order script. This time it has to choose whether it is in front or behind the last sprite that was looked at. It does this by looking in the depth list and comparing its own depth to that value). If it's behind, then it does nothing (because we know it is already behind), otherwise we move it forward 1 layer. Then we store our z value in the list at the same position. 3) We process the third sprite, doing the same as 2, only now we are comparing out z value to the 2 other items in the list... This process continues for every sprite/clone in the project. What we have implemented here is called "insertion sort". It's not the fastest sort (but not the slowest either). But it is ideally suited to the way the broadcast system is working in scratch.

Project Details

Project ID484468628
CreatedFebruary 6, 2021
Last ModifiedFebruary 6, 2021
SharedFebruary 6, 2021
Visibilityvisible
CommentsAllowed

Remix Information

Parent ProjectView Parent
Root ProjectView Root