Skip to content

Please update your browser

Your browser version is not supported by this site. CS First may not work properly. Learn more

2. Move the Sprite


In this screencast, you will use events to move the player 1 sprite when the arrow keys are pressed. To start, click on the player 1 sprite. In this game, the user needs to be able to move the sprite: To find blocks that move the sprite click on motion. If you’re not sure which blocks to choose, double click on a few to see what they do. For example, if you double click on “move 10 steps,” you see that it moves the sprite forward, so you can choose to add it to the program.

Double clicking on the “turn” blocks the sprite, so drag both of those out as well.

You now have three blocks in your program, but the only way to run them is to click on them. That doesn’t make for a very exciting game.

To fix this, use event blocks to run this code when the user presses the arrow keys.

Click on the events menu. Event blocks tell the computer when to run code. You could use an event block that would run code “when” the green flag is clicked, or “when” the sprite is clicked. But, for this game, you will use a “when” key pressed block.

This block has a drop down menu that shows all key press options. The sprite should move forward when you press the up arrow, so select “up arrow” and attach this block to the “move 10 steps” block.

Try this by pressing the up arrow. Great!

Now, this sprite moves forward when the up arrow is pressed.

You can add more keypress events to turn this sprite clockwise with the right arrow, and counterclockwise with the left arrow.

Great! Now I have a basic racing game and it's your turn to create your own.

Once this screencast is finished, program the player 1 sprite using: 1) A keypress event for up, left, and right arrow keys 2) A movement block for each event Remember, if you have a question, you can ask a neighbor or use a sticky note to get the attention of your CS First Guru.

After you have completed this step, go to the next screencast by pressing the green arrow.

arrow_backward Back
Next arrow_forward
  1. Create an event for the three arrow presses.
  2. Add a "move" block to each arrow-press event.