Loops and Sound in Scratch
In the last lesson, you learned how to make a sprite move and turn in Scratch. In this lesson, you will learn how to add a new sprite, repeat blocks, and add sound to your programs.
Adding Another Sprite
The cat sprite is nice, but Scratch also has many other sprites that you can use in your projects. You can even draw your own sprites!
Open your project from last time. To add a new sprite to your project, you can click on one of the options by the words “New Sprite:” in the Sprites area of the screen. For now, click on the icon for Choose sprite from library.
A long list of sprites should appear on your screen. Select a sprite that you like, and click OK. Now the Sprites area on your screen should contain two sprites.
Each sprite in a Scratch project has its own scripts. To see the scripts for a particular sprite, make sure that sprite is selected in the Sprites area.
Exercise: To review what you learned last time, write a program that makes your new sprite move in a square. How many blocks did you use?
You had to repeat the move and turn blocks to make the sprite move in a square. To make your program simpler, you can use the forever block in the Control menu. This block is called a loop. A loop is a programming structure that repeats a portion of a program. Look at the Control menu. Which of the other blocks do you think might be loops?
Other blocks can be placed inside the forever block. The forever block repeats the blocks inside it until you press the stop sign to stop the program.
Exercise: Try out the program below to make the sprite move in a square. The green pen commands are located in the Pen menu. You can use them to draw a sprite’s path on the screen.
The repeat block is a loop that repeats the blocks inside it a certain number of times. For example, the program below makes a sprite tilt back and forth five times.
Exercise: Modify your program to make the sprite move in a square exactly one time. Can you make the sprite move in a hexagon?
You can add sounds to your program to make it more fun. You can use the Scratch library of sounds, or you can record your own.
Click on the Sounds tab at the top of the screen. Then click on the icon for Choose sound from library. The sound library will appear. You can try out different sounds and select one for your project.
You can also use the microphone icon to record a new sound. Be sure to give your new sound a name. Use the button with the circle to start recording and the button with the square to stop.
Click on the Scripts tab to return to your scripts. Then click on the Sound menu. You can use the play sound until done block to play the sound you selected or recorded.
Exercise: Write a program that uses loops to make a sprite dance to music.
You can also use the play note and rest blocks (Sound menu) to create music. The play note block requires two numbers. The number on the left determines the pitch of the note; it should be between 15 and 130. Instead of entering a number, you can also select a piano key on the pop-up menu. The number on the right determines the length of the note; it can be any positive number.
The rest block can be used to separate notes. During the rest, no sound is played. The number in the rest block is the length of the rest. It can be any positive number.
Exercise: Use the play note and rest blocks to create a short song. Place the set tempo block (Sound menu) at the start of your song. How does changing the number in this block affect the music?
Exercise: Make a sprite move in rhythm with your song, and then use a loop to make the sprite repeat the song and dance.
Optional: Some sprites in Scratch have multiple costumes that you can use within a loop to make it look like the sprite is walking, flying, or dancing. Watch this video tutorial to learn more; then try to make a different sprite walk, fly, or dance.