Skip to content
Transcript

Using code to add movement can help tell your audience about your hero.

In this video, you will program your hero sprite to move when the arrow keys are pressed.

To start, drag out a “change y by” block from the Motion menu.

“Y” is the vertical, or up and down, location of your sprite on the stage.

Use a positive number to move your hero up.

Program your sprite to move up when the up arrow key is pressed. From the Events menu, drag out a “when key pressed” event and attach it to the “change y by” block.

Select “up arrow” from the drop-down menu.

Test your code.

Great! To make your sprite move more OR less, adjust the values in the blocks.

Now add code that tells the computer to move your hero down when you click the down arrow key!

To do this, duplicate your code and select the down arrow key from the dropdown menu and update the value with a negative number.

Test your code.

Make your hero sprite move left and right with a “change x by” block.

“X” is the horizontal, or side to side, location of your sprite on the stage.

Use a positive number to program your sprite to move to the right.

From the Events menu, drag out a “when key pressed” event and attach it to the top of the “change x by” block.

Select “right arrow” from the drop down menu.

Duplicate this code and update the values to program your hero to move left when the left arrow is pressed.

Test your program again.

Awesome! Now your hero moves up, down, and side to side with the arrow keys.

Once you’ve programmed your hero to move, try “Fly Over Buildings” to keep adding to your project.

Then, come back to this page to check out more videos! You can try any video you like.

Choose an Add-On

Start here
Move Your Hero

Make your hero move up and down when arrow keys are pressed.

Fly Over Buildings

Program buildings to move across the screen, so your hero appears to fly.

Add Background Music

Set the scene for your hero by adding sound to your project.

Show Off with a Super Spin

Help your hero do great things with this spinning move.

Keep Score

Create a game by programming your hero to collect objects.

Support Your Hero

Add another character to help your hero.

Draw Your Own Hero

Use the Paint Editor in Scratch to draw your own hero.

Instructions

Para hacer esta actividad en español, haz clic aquí.

 Students

  1. Watch the introduction video.
  2. Open the starter project link and choose a sprite for your hero.
  3. Return to this page and watch more videos below.

Teachers

  1. Visit the Hour of Code teacher resource page for instructions.