Please update your browser
Your browser version is not supported by this site. CS First may not work properly. Learn more.
In this video, you'll program the backdrop
to change when the character sprite touches
an entrance sprite.
First, drag the character sprite
to where you want it to start.
A good spot is somewhere away from the entrance sprites.
Then, click the "motion menu" and add
a "go to" block right below the "when flag clicked" block.
Next, select the house entrance sprite
and program the backdrop to change.
Click the "looks menu"
and drag out a "switch backdrop" block.
Click the drop-down and select "house".
Click this block to run it.
Drag out another "switch backdrop" block,
select "town" and click to return to the original backdrop.
The town backdrop should always show at the beginning
of the program.
So add a "when flag clicked" block from events
to the top of that block.
Next, program the backdrop to change
if the sprite is touching the player sprite.
Select "control" and place an "if" block
around the "switch backdrop to house" block.
Select "sensing" and drag
a "touching" block into the condition.
Click the drop-down and select "character".
Now that you have an if statement,
make it run for the entire program.
Click "control" and place a forever loop
around the "if" block.
Then, click "events" and add a "when flag clicked" block.
Click the flag to try it out.
Move the player sprite with the arrow keys
to make it touch the house entrance sprite.
The backdrop changed.
It looks a little goofy now
because all of the entrance sprites
are still on the stage.
Make all of the sprites hide at the same time
using "broadcast" and "when I receive" blocks.
Drag a "broadcast" block under
the "switch backdrop to house" block.
Change the name of the message to "hide entrances".
Drag out a "when I receive" block and change the message
to "hide entrances".
Then, select "looks" and drag out a "hide" block.
Click the flag to try this out.
Move the character sprite until it touches
the house entrance.
Great, the house was hit.
Click the flag again.
The house sprite is still hidden.
Program it to show each time the backdrop switches to town.
Click "events", drag out a "when backdrop switches" block
and select "town" from the drop-down.
Then, click "looks" and add a "show" block.
Try it out one more time.
Click the flag and move the player to the house.
The backdrop changes and the house sprite hides.
Click the flag again and the sprite reappears
and the backdrop changes back to start.
Now that you've successfully programmed
and tested your code for one entrance sprite
add it to the other entrance sprites.
To copy code between sprites,
click and drag it on top of each sprite.
Click and drag the "when I receive",
"when backdrop switches"
and "when flag clicked" block stacks
on top of the cave entrance sprite.
Click the cave sprite and make sure
all the code successfully copied.
Click the flag and use the arrow keys
to make the character go to the cave sprite.
Oops, the backdrop changed to the house backdrop.
Click the drop-down and the "switch backdrop" block
and select "cave".
Next, repeat this process for the forest entrance sprite.
Drag over the three block stacks
and change the value
in the switch backdrop block to "forest".
Click the flag to test each entrance sprite.
If the backdrop doesn't switch to the correct one
check the value in the "switch backdrop" block.
Now, it's your turn.
Program the game to begin on the "town" backdrop
using a "when flag clicked"
and a "switch backdrop to town" block.
For each entrance sprite,
program the backdrop to change using
the "touching", "switch backdrop", "when flag clicked",
"forever" and "if" blocks.
Hide all entrance sprites using
a "broadcast" block, a "when I receive" block
and a "hide" block.
Show all the entrances with
"when backdrop switches to town" and "show" blocks.