Skip to content

Please update your browser

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

Transcript

In this screencast, you'll learn how to add sound effects to your projectile sprite so it makes a noise when it touches your main character sprite. Watch this screencast to learn the steps, and then try them out. The starter project already includes a "make noise" block, but it doesn't do anything yet because it has not been defined. If you remember from day 1 of this club, when you create a custom block or process, you also need to tell the computer what it should do when the block is used. Drag out a “play sound” block and place it under the “define make noise” block. Choose one of your sounds from the drop-down. Run the code to see what happens. Perfect! The sound plays when the projectile sprite hits the main character sprite.

But, you want the sprite to make a different noise for each of its four costumes. To make that happen, use an if-then statement from the control menu. This statement needs to check IF the costume equals a certain costume number, THEN play a sound. To create that code, click on the operator menu and put an “equals operator” block inside the if statement. Under the looks menu, drag the “costume number” block into the “operator” block, and type a "1" into the white value box of the operator block. The code now reads: "If the costume number equals 1, then play a certain sound." Try it out. Nice! In this example, if the costume is number 1, the bird, then the bird sound plays. Otherwise, no sound plays at all.

You want a sound to play for each costume, so right-click on the If statement and choose duplicate, then change the values of the costume number and the “play sound” block. This will make a different sound play for each costume. You can always click back on the costumes tab to check the number of a particular costume.

Now, it's your turn. Add an If-then block to the “define make noise” stack, and create code that says "If the costume equals 1, then play a sound." Do this for all four of the projectile sprite’s costumes so each plays a different sound. Remember, if you get stuck, ask your neighbor or put up your sticky to get the attention of your CS First Guru.

arrow_backward Back
Next arrow_forward
Instructions
  1. Make the "play sound" block play a sound.
  2. Make the sound play if the costume equals a certain costume number.
  3. Make a different sound play for each costume.