In this add on,
program one or more sprites to move
when the keys on the keyboard are pressed.
This example programs a sprite to move left and right,
and to jump, but program any movements that you like.
To start, select a sprite to control with the keyboard.
Next, program the sprite to move.
Click motion, and drag out a change x by block.
In Scratch, x represents the left and right values
on the stage.
Click to run it.
Great, the sprite moves right.
Drag out another change x block
and make the value negative.
Click to test.
The sprite moves left.
To make the sprite jump up and down,
use two change y by blocks.
In Scratch, y values represent spots
between the top and bottom edges of the stage.
Click one of the blocks to test.
A positive y value moves the sprite up.
Change a block to a negative value and click.
In this example, the sprite jumps up and comes back down.
To do this, connect the change y by block
and place a wait block from the control menu between them.
The sprite moves up, waits, then comes back down.
Change the value in the wait block
to make the sprite jump faster, or even slower.
Now that the sprite has left, right, and jump movements,
program this code to run when the keys are pressed.
Each movement code stack should run if a key is pressed.
Click control, and add an if block to each movement
Then, click sensing, and add a key press block to each.
Changing x by a positive value will move the sprite right.
Select a key to move a sprite right.
Changing x by a negative value will move the sprite left.
Choose a key to move the sprite left.
Then, select a key to move the sprite up and down.
To run this code for the entire program,
add a forever loop from the control menu
around the three if statements.
Run this code at the start of your program
by adding a when flag clicked event.
Click the flag to test.
Press the arrow keys, and awesome.
The sprite moves left, right, and jumps.
Tinkle with the values in the change x and change y blocks
to change the movement of your sprite.
To program the other character sprite or the boat,
copy over the code by dragging it on top of the sprite.
Then change the key pressed conditions.
Finally, tell the user how to use your program.
Click see project page and add instructions
for which keys to press.
Click see inside to return to your code.
Now it's your turn.
Program different movements using change x
and change y blocks.
Program each movement code stack to run,
using if and key pressed blocks.
And lastly, program the code to run for the entire program
using forever and when flag clicked blocks.
Add sound effects to your story.
Draw and animate a sun sprite.
Program a sinking ship in your story.
Program a Second Scene for your Story.
Draw and program clouds that move.
Program one or more sprites to move when keys on the keyboard are pressed.
Sign in to track your progress and earn badges