Projects
Rock band
Learn how to code your own
musical instruments
Step 1 What you will make
Learn how to code your own musical instruments!
Step 2 Sprites
Open a new Scratch project (http://rpf.io/scratch-new).
It looks like this:
If you are signed in to your Scratch account, type the title of your
project into the project title box at the top of the screen:
Tip: Give your projects helpful names so that you can easily find them
when you have lots of projects.
If you are not online or don’t have a Scratch account, you can save a
copy of your project by clicking on Save to your computer instead.
The cat sprite that you can see is the Scratch mascot. You don’t need
it for this game, so get rid of it by clicking on the X in the corner.
Next, click on Choose sprite from library to open up a list of all the
Scratch sprites.
Scroll down until you see a drum sprite. Click on a drum to add it to
your project.
Step 3 The Stage
The Stage is the area on the right, and is where your project comes to life.
Think of it as a performance area, just like a real stage!
At the moment, the stage is white. Add a backdrop to it by clicking on
Choose a backdrop.
Click on Indoors in the list at the top. Then click on a backdrop you
like.
Click and drag the drum to the bottom of the Stage.
Your stage should now look similar to this (we used the Theater
backdrop):
Step 4 Make a drum
Now you will add code to your drum so that the drum makes a sound when
it’s clicked.
First add the Music extension so you can play instruments:
Click on the Add extension button in the bottom left-hand corner.
Click on the Music extension to add it.
Click on the drum sprite, and then drag these two blocks into the
code area on the right:
when this sprite clicked
play drum (1) Snare Drum for 0.25 beats
Make sure that the blocks are connected together (like LEGO bricks).
Click on the drum to try out your new instrument!
Step 5 Make a singer
Now you will add a singer to your band!
Add a singer sprite to your Stage.
Add a sprite from the Sprite Library
Click on Choose a Sprite to open the Sprite Library:
You can search for a sprite, or browse for one by category. Click on a sprite to add it to
your project.
Add a sound to your singer sprite.
Make sure that you have selected your singer sprite, then click on the
Sounds tab, and click on Choose a sound:
Click on Voice in the list at the top, and then choose a sound to add to
your sprite.
To use the sound, add the following code blocks to your singer sprite:
when this sprite clicked
play sound singer1 until done
Test your code. Click on your singer on the stage and see what
happens. Does she sing?
Step 6 Costumes
Now you will make your singer look like she’s singing! Change how your
singer sprite looks when it’s clicked by creating a new costume.
Click on the Costumes tab, and you’ll see the singer costume.
Right-click on the costume and then click on duplicate to create a
copy of it.
Click on the new costume (called ‘Singer2’), and then select the line
tool and draw lines so it looks like your singer is making a sound.
The names of the costumes aren’t very helpful at the moment. Type
into the text boxes of the costumes to change their names to ‘not
singing’ and ‘singing’.
Now that you have two different costumes for your singer, you can
choose which costume is displayed! Add these two code blocks to
your singer sprite:
when this sprite clicked
switch costume to singing
play sound singer1 until done
switch costume to not singing
The code block for changing the costume is in the Looks section.
Click on your singer on the stage. Does she look like she is singing?
Challenge!
Challenge
Now make your drum look like it’s being hit!
Remember to test that your new code works!
Add more instruments to make your own band! You can create any
instruments you like — look at the available instrument sprites and
sounds to get some ideas.
when this sprite clicked
set instrument to (1) Piano
play note 60 for 0.25 beats
Your instruments don’t have to be realistic though. For example, you
could make a piano made out of muffins!
Can you change the sound that the drum makes when it’s clicked?
Can you also get the drum to make a sound when the space bar is
pressed? You’ll need to use this event block:
when space key pressed
Paint your own sprites!
If you have a microphone, record your own sounds, and you can
even use a webcam to hit your instruments!
Why is my sprite 'jumping' when it changes costume?
When creating your own sprite, you may find that when you click the sprite, it ‘jumps’ as it
changes costume. This is because the two costumes aren’t centered in the same place.
To fix this, make sure that the centres of your sprite’s costumes are the same.
Published by Raspberry Pi Foundation (https://www.raspberrypi.org) under a Creative Commons license (https://crea
tivecommons.org/licenses/by-sa/4.0/).
View project & license on GitHub (https://github.com/RaspberryPiLearning/rock-band)