In this video, you’ll program the lightning to flash using loops and “change backdrop”blocks. So far, you’ve created code only for a sprite.
In this video, you’ll program the stage. To start, select the stage. You can programthe stage to do almost everything a sprite can do, except move.
Next, look in the backdrops tab. You’ll see that there are two backdropsin the starter project: one for the night sky, and one that’s bright like a lightningflash. If you click quickly between these two backdrops,you can see what the lightning flash will look like. You will program the computer tomake that flash happen much faster than you can click.
To start, program the stage to change backdrops. Click looks, and drag out a “next backdrop”block. Click the block to test it. You should seethe backdrop change. Click it again, and see that the backdrop switches back to the nightsky. Well, lightning usually flashes more thanonce. Earlier, you used a “forever” block tomake something happen over and over. But, this time you only want the lightning to flasha few times, not to keep repeating forever like the rain. Use a “repeat 10” blockto limit the number of times the lightning repeats.
Click it to try it out. Great, the backdrop changed, and the lightningflashed, 10 times. Tinker with this number until you like how many times the lightning flashes.
You might notice that if you enter an odd number in the “repeat” block, thelightning continues to show after the final flash. If this happens, click the “nextbackdrop” button again, and change the value in the “repeat” block to an even number.
This example will repeat 4 times. If the lightning is flashing too fast, consider adding a “wait”block inside your loop and changing its value to a really small number, like .1 or .01.
This will make the computer wait between switching backdrops, so the lightning flashes more slowly.
Great! Now that the lightning flash is programmed, you need to tell the computer when to flashthe lightning. Add a “when flag clicked” event to thetop of this block stack. Try it out by clicking the flag.
Great! The lightning flashes at the beginning of the story.
Test your code often, so you catch bugs along the way.
There’s just one problem. If you click the stop button when the lightning flashes, thenthe program will start with the yellow backdrop. To fix that bug, add a “switch backdropto Night Sky” block under the “when flag clicked” block. Great! Now, whenever theprogram runs, it will start on the Night Sky backdrop.
In the next video, you’ll program the lightning to flash randomly throughout your story.
Now, it’s your turn: 1) Select the stage.
2) Program the backdrop to change with a “next backdrop” block.
3) Use a “repeat” block to make the backdrop change a specific number of times.
4) Start the program with a “when flag clicked” event.