Moving Up and Down
Moving Up and Down
1. Click and drag a “when space key pressed” block from the Events category in the Block Palette.
2. Click on the drop-down menu in the “when space key pressed” block and select the “up arrow”. This will tell your Sprite that when you press the up arrow it will run the code underneath it.
3. Click and drag a “change y by 10” block from the Motion category in the Block Palette. Attach this block to the "when up arrow key pressed" block. The “change y by 10” block tells your sprite to move up the y-axis because the number is getting bigger. Therefore when you press the up arrow key your Sprite should move 10 places upward on the y-axis to a new y-coordinate.
Your code for the up arrow will now look like this:
4. Click and drag a second “when space key pressed” block from the Events category in the Block Palette.
5. Click on the drop-down menu in the “when space key pressed” block and select the “down arrow”. This will tell your Sprite that when you press the down arrow it will run the code underneath it.
6. Click and drag a “change y by 10” block from the Motion category in the Block Palette. Attach this block to the “when down arrow key pressed” block.
7. Click on the white bubble inside the “change y by 10” block and change this number to -10. This will tell your Sprite to move down the y-axis because the number is getting smaller. Therefore when you press the down arrow key your sprite should move 10 places downward on the y-axis to a new y-coordinate.
Your Code Area should now have three Event blocks with code under each block like the image below:
8. Test your code! Start by pressing the green flag button at the top of your Stage to run your code. When you press the up or down arrow does your Sprite move correctly along the y-axis to a new y-coordinate?
Views | |
---|---|
1 | Total Views |
1 | Members Views |
0 | Public Views |
Share by mail
Please login to share this webpage by email.