# Unit 3 Lesson 11 question

**URL:** <https://forum.code.org/t/unit-3-lesson-11-question/38570>\
**Category:** Coding and Debugging Help\
**Created:** [October 25, 2023, 5:52pm UTC](https://forum.code.org/t/unit-3-lesson-11-question/38570 "2023-10-25T17:52:52Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![dvillarreal](https://avatars.discourse-cdn.com/v4/letter/d/db5fbb/32.png) [@dvillarreal](https://forum.code.org/u/dvillarreal)\
**Post date:** [October 25, 2023, 5:52pm UTC](https://forum.code.org/t/unit-3-lesson-11-question/38570/1 "2023-10-25T17:52:52Z")

</div>

Just a question. Is it only possible to put shapes on top of sprites? Or is there a way to have some shapes on top of a background and then some shapes behind other sprites?

drawSprites redraws all the sprites, so I can’t figure out how to interlayer my sprites and shapes. I can only do sprites first and then shapes.

I don’t want the stars on the castle (the student made it work by the random numbers used), but it would have been easier if layering was possible.

> **[Check out what I made](https://studio.code.org/projects/gamelab/F4Aa0uIG27UqxLoJvzc90P-Q91am6f-T3miYFmMUkxE)**
>
> I wrote the code myself with Code.org

---

<div class="post-metadata">

**Author:** ![varrience](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.code.org/varrience/32/8042_2.png) [@varrience](https://forum.code.org/u/varrience)\
**Post date:** [October 26, 2023, 5:13am UTC](https://forum.code.org/t/unit-3-lesson-11-question/38570/2 "2023-10-26T05:13:47Z")

</div>

well you can group specific sprites to be drawn at different times and adjust them in the draw order you want  
**drawSprites()**: _takes a group or draws all current sprites that have been created_  
**sprite.depth** : _declares when they should be drawn in the process_  
**drawSprite()**: _draws a singular sprite rather than updating the full thing_  
I’m not too sure how you want to layer your sprites so i hope this will solve the issues you’ve been having best of luck!

---

<div class="post-metadata">

**Author:** ![mwood](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.code.org/mwood/32/4941_2.png) [@mwood](https://forum.code.org/u/mwood)\
**Post date:** [October 26, 2023, 6:18am UTC](https://forum.code.org/t/unit-3-lesson-11-question/38570/3 "2023-10-26T06:18:58Z")

</div>

@dvillarreal ,

As @varrience suggests, you can use the singular drawSprite() command to draw a single sprite. It’s not listed in the documentation, but it does work and is useful in a few situations. Make sure to include the name of the sprite inside the parenthesis like this:

`drawSprite(castle);`

This would also have to be done in text mode as there isn’t a block for it.

I haven’t used sprite.depth much, but it could also work. Another key concept, however, is realizing that the order that the sprites are declared at the beginning of your code is also the order they will be drawn, so if you want one to be on top of another, declare it after that one. If you declare the background sprite first, all other sprites will be drawn on top of it.

Hope this helps clarify a little.

Mike

---

<div class="post-metadata">

**Author:** ![dvillarreal](https://avatars.discourse-cdn.com/v4/letter/d/db5fbb/32.png) [@dvillarreal](https://forum.code.org/u/dvillarreal)\
**Post date:** [October 26, 2023, 6:24pm UTC](https://forum.code.org/t/unit-3-lesson-11-question/38570/5 "2023-10-26T18:24:45Z")

</div>

I don’t have an issue with the order of the sprites being drawn to each other. I need the background (which is a sprite) then some shapes (which are rects) and then a sprite on top of the rects. I need to be able to place rects in between layers of sprites.

I tried the drawSprite() command, but I got a warning that the drawSprite() hasn’t been declared yet.

---

<div class="post-metadata">

**Author:** ![mwood](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.code.org/mwood/32/4941_2.png) [@mwood](https://forum.code.org/u/mwood)\
**Post date:** [October 26, 2023, 6:59pm UTC](https://forum.code.org/t/unit-3-lesson-11-question/38570/6 "2023-10-26T18:59:16Z")

</div>

@dvillarreal,

Sorry I gave bad information … I will update my post to reflect the correct information.

You need to use drawSprite(castle) WITHOUT quote marks. I said to put it in quote marks and that was wrong information.

You will still get that error message (yellow triangle) but it will work and it won’t exit out of the program.

Here’s a link to my version of your project with the castle being drawn separately. Notice the knight is now behind the castle, so you may have to look at order of sprites so he stays in front.

> **[Check out what I made](https://studio.code.org/projects/gamelab/qkFYoyiNPweC-daCKrpAkkt64Pbg-QHQc60LNY5qGW0)**
>
> I wrote the code myself with Code.org

Sorry for the bad info yesterday.

Mike

---

<div class="post-metadata">

**Author:** ![dvillarreal](https://avatars.discourse-cdn.com/v4/letter/d/db5fbb/32.png) [@dvillarreal](https://forum.code.org/u/dvillarreal)\
**Post date:** [October 26, 2023, 7:30pm UTC](https://forum.code.org/t/unit-3-lesson-11-question/38570/7 "2023-10-26T19:30:52Z")

</div>

Awesome!  
Thank you so much!
