Code Your Sprite to Fly Around the Stage
Code Your Sprite to Fly Around the Stage
1. Click on the Sprite in the Sprite Pane so that it is ready to receive code.
2. Drag a “when space key pressed” block from the Events category in the Block Palette into the Code Area. This yellow Events block will tell your code to run when you press the space key on your keyboard.
If you click on the drop-down menu on this block, you can choose a different key on your keyboard as the input for starting your code. You can choose a letter, number or arrow key.
3. Go to the dark blue Motion category in the Blocks Palette. This category has blocks that will control the movement of your Sprite in different ways. Select the “glide 1 sec to random position” block. Drag this block onto the Code Area and snap it underneath the “when space key clicked” block.
This Motion block will have your Sprite glide to a random position on the Stage and it will take one second for it to reach its destination.
Press the space key on your keyboard to test your code! When you hit the space key, you’ll notice that the Sprite glides to a random position on the Stage and it will take one second!
If you keep pressing down on the space key, your sprite will continuously glide in a different direction every second.
Views | |
---|---|
1 | Total Views |
1 | Members Views |
0 | Public Views |
Share by mail
Please login to share this webpage by email.