Layering Sprites with Shapes


Hello All!

My students and I have run into a problem I can’t solve. We are trying to layer background, sprite, shape, sprite. However, when we call drawSprites() on the second sprite, it redraws the first sprite (already drawn) on top of the shape. I have tried using sprite.depth and I have tried writing separate functions to draw the sprites in hopes of limiting the scope, but no luck. Can anyone help me make this work?

Thanks in advance!!



add the var and sprite animation after first draw sprite. I did this in level 14 and it draws the bell on top of the snake…


Thanks so much for your reply! Yes, it does draw the bell on top of the snake, but the snake is no longer behind the bars - we are trying to get the snake to stay on its original layer instead of moving to the top.


I don’t think this is possible to do with the blocks that you have in this lesson. drawSprites draws every sprite at the same time, so it’s impossible to draw a shape between them.

Once you have the “visible” property, you can do it, though. You’d need to create the first sprite, draw it, then make it invisible. Then draw your shape, then create and draw the second sprite. I have an example here:

There are other ways to do this that don’t feel as much of a workaround, but they rely on blocks that aren’t in the curriculum.



Thank you, Elizabeth! That works perfectly. My kiddos are already flipping back and forth between blocks and code, so they can type it in. I really appreciate the assistance!