panel has buttons for playing back
sounds. Mess around a bit to get the effect you’re looking for.
side-to-side position, and Y relates to the
bottom-to-top position. The center of
the screen is (0, 0). You can see how the
screen is organized by selecting the stage.
Go to the Backgrounds tab and import a background. In the main directory
of the backgrounds you’ll see a special
background image called the XY-grid.
This tool shows the XY coordinate system and is very handy when you’re trying
to figure out where you are on the screen.
Of course, you can replace it with some
other background when you’re ready to
move on. Figure 3 shows the Scratch editor with the grid showing.
The Move To button in the Motion panel
moves a sprite to a particular spot immediately. It’s easiest to determine positions
if you start with the grid as a background.
Also, when you first move to the Motion
panel, the Move To and Glide To buttons
are pre-set with the current position.
You can’t make a sprite completely
leave the stage, but you can hide and
show sprites. When the animation starts,
both sprites should be invisible.
Move your first sprite to the center of
the scene and say something (if you want).
The easiest way to synchronize between two or more sprites is by using the
message mechanism. Any sprite can send
a message. (There’s a Broadcast command on the Control menu.) Choose
New to create a new message.
Every sprite can also listen for mes-
sages. The Control panel includes a spe-
cial command called When I Receive.
You can use this command to listen for
any messages broadcast by any sprite.
This works much like actors on a stage.
In my example, when the program starts,
the cat and dog are both hidden off stage.
When the cat is finished with his line, he
broadcasts the “CallDog” message. The
dog is patiently listening for “CallDog”
and moves onto the screen when he
hears his message. Messages represent an
extremely powerful mechanism. My joke
program uses a number of other mes-
sages to pass control from one sprite to
Up, Down, Left, and Right
The difference between an animation
and a game is user control (Okay, there are
a few other factors too, such as a goal and
an obstacle, but go with me here.) Your
next job is to make a sprite that moves up
when you press the Up arrow, down when
you press the Down arrow, and (I think
you’re catching on) left and right when the
appropriate arrows are pressed.
Here’s an example: www.aharrisbooks
User input involves getting some kind
of signal from the user, normally from
the keyboard or the mouse. This is done
with a combination of two types of buttons: ( 1) if statements and ( 2) sensors.
When you use the word if in English,
you’re normally testing to see if something is true. That’s exactly how if statements work in Scratch. On every frame
(several times a second), we need to
check to see if a key is being pressed.
This means you need a Forever loop.
Inside that loop, you’ll need an If command. (Both are found in the Controls
tab.) Note that If has a little hexagon
shape inside it. This indicates you need a
condition (a true or false test).
Look into the Sensing tab and you’ll see
a great number of tests. The one you’re
looking for is Key <space> Pressed. Now
place a movement command, and when
you press the appropriate key, you’ll
move in the indicated direction. Figure 4
shows this in action.