Skip to content

Please update your browser

Your browser version is not supported by this site. CS First may not work properly. Learn more

3. Éclairs

Transcript

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 program the stage to do almost everything a sprite can do, except move.

Next, look in the backdrops tab. You’ll see that there are two backdrops in the starter project: one for the night sky, and one that’s bright like a lightning flash. If you click quickly between these two backdrops, you can see what the lightning flash will look like. You will program the computer to make 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 see the backdrop change. Click it again, and see that the backdrop switches back to the night sky. Well, lightning usually flashes more than once. Earlier, you used a “forever” block to make something happen over and over. But, this time you only want the lightning to flash a few times, not to keep repeating forever like the rain. Use a “repeat 10” block to limit the number of times the lightning repeats.

Click it to try it out. Great, the backdrop changed, and the lightning flashed, 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, the lightning continues to show after the final flash. If this happens, click the “next backdrop” 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 flash the lightning. Add a “when flag clicked” event to the top 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, then the program will start with the yellow backdrop. To fix that bug, add a “switch backdrop to Night Sky” block under the “when flag clicked” block. Great! Now, whenever the program 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.

arrow_backward Retour
Suivant arrow_forward
Instructions
  1. Programme le changement d'arrière-plan.
  2. Fais en sorte que l'arrière-plan change un nombre précis de fois.
  3. Attends entre les changements d'arrière-plan.
  4. Lance le programme lorsqu’un utilisateur clique sur le drapeau.
Indice : si l'arrière-plan s'arrête sur "Éclairs", clique sur le bloc "Arrière-plan suivant", ou sélectionne "Ciel de nuit" dans l'onglet Arrière-plans.