SCRATCH Lesson 4: Create a Music Sprite

In this lesson 3, we make our sprite dance. In lesson 4, I will show you how to make him dance to the beat. And not just to the beat but to the Hip-Pop beat! (Note: the video below used Scratch 1.4. For instruction with Scratch 2.0, please read the article)

(Note: Updated for Scratch 2.0 )

Step 1: Create a Music Sprite

Let’s create a Music Sprite or a sprite that controls playing and stopping of background music.

Click on the alien-looking icon  (choose sprite from library) to choose a costume from library.

Browse to select whatever costume you like. I chose the drum.

 

Rename this new sprite to “hip-pop”. It’s seems big for me so I shrink it with “Shrink Sprite” tool.

 

Then click anywhere outside of the stage to get back to the cursor.

Step 2: Move Music Loop to the Music Sprite

Drag the Music Combo Block from dancer1’s Scripts Tab.

Delete the combo block that plays music clips from “dancer1”.

 

Select “hip-pop” sprite, click on “Sound” tab, and click the speaker icon to import  “beat box1” from the music library

Step 3: Turn Music On and Off

To turn music on and off, we need to create a virtual switch. Like a real switch, a virtual switch can be on or off. To create a virtual switch, we use Variables. Select “Variables” Tool Box, and click “Make a variable” button. Then enter “switch” for Variable name.

 

I would like this switch to work this way:

When the animation first starts, the music is playing and the switch is on. Click the “dancer1” sprite to turn it OFF, and click the “hip-pop” sprite to turn it ON again. If the switch is ON, music is ON; if the switch is OFF, music is OFF.

For this switch to work, we need following blocks:

  • one  block from  tool kit

  • one  block from  tool kit

  • one  block from  tool kit

 

For  sprite, we will add three new combo blocks. The first combo block turns the switch ON (set music on to 1) when  is clicked.

 

The second combo block turns the switch ON again (set music on to 1) when “hip-pop” is clicked.

For  sprite, we will add one combo block. This combo block will turns the switch OFF if “dancer1” is clicked.

 

Your “dancer1” sprite should have these combo blocks.

 

Your “hip-pop” sprite should have these combo blocks.

Now you are ready to test. Click the green flag to start, click dancer sprite to stop the music, and the drum to start it again.

You can find the finish project here: http://scratch.mit.edu/projects/1616790/