Scratch Responding to Input
Mar 19, 2016
Scratch
Responding toInput
Lesson Objectives
● Look at what the term input means● See how to control a sprite using keys● See how to move a sprite in small steps● Change sprites (or costumes)
Movement costumes
● Before we start coding we need our costumes!
● We need to create a sprite for each direction they will be facing.
● This can be done by rotating the sprite and tweaking.
Importing costumes
● This can be done on the costumes tab.
● Simply click import and load up the 4 images
Responding to key press
● Under control is the “when x key pressed”
● Anything connected to this will run when that key is pressed.
● You can choose the key by selecting from the drop down
Sequence of events
● What are the sequence of events for going left?
● And no it is not just “go left”!
Sequence of events
● Change costume to “left”● Move 4 spaces.
● This will be the same for each key press● You will also need to choose the right axis (x
or y)
Solution
● Notice that it is repeated for each key press
● Left and right use x● Up and down use y
Activity
● Create a new scratch file● Create a sprite with 4 costumes (up, down,
left and right)● Import your spite and costumes● Get your sprite to move!
Finding a sound loop
● Do a search for “sound loops” to find a short bit of music to play.
● Flash kit is a great place to start
Import sound
● You can import a WAV or MP3 file
● This is imported into a sprite the same way a costume is
On click play some music!
● To play the sound we need the code on the right.
● Note that the colours represent the section each command came from.
● You could loop the sound if you wanted to!
Activity 2
● Add music when you click on your sprite