Today you are going to use some fairly complicated code to make different levels in Scratch. Here’s what you are aiming to do:
- Add objects for your character to collect (if you haven’t already done it)
- Program your game to move to the next background or level when you collect the object
- Make objects disappear when you move to the next background or level
Instructions
First, make sure you have drawn 6-10 backgrounds on the Stage. These will act as your different levels.
Next, add in a sprite to collect on background 1. You may, for example, like to collect a key. The character you are controlling will be called Sprite 1 (unless you have renamed it) so the object you’re collecting (let’s assume it’s a key) will be called sprite 2.
Once your object is added to your game, click on Sprite 1 (your character) and write the following code in the Scripts tab:

This code tells the game to go to the next level when the character collects the object.
After that, click on the Stage and go to the Scripts tab. Add in the following code:

This code tells the background to change when your character goes to the next level.
You should now be able to move from one background to the next when your character collects the object. However, you will still notice a big issue: when you move to Level 2 the object is still there! There’s a (slightly) complex bit of code which you can add to fix this problem:
First, click on the object you want to show/hide and go to the Scripts tab. Enter the following code:

This code tells the object only to appear when background 1 is shown, and to hide the rest of the time (for example, when on levels 2, 3, etc…)
Once this is complete, you can add other objects for the other levels and use the same code to make objects appear on other levels. You will just need to change the background number.
It’s a tricky one this week! Good luck!