How to Make Your Sprite Move with Scratch on the Raspberry Pi
Sprite xperimenting with Scratch on the Raspberry Pi is easy. To try out different blocks, just click them in the Blocks Palette. For example, try clicking the block to move 10 steps, and you should see your cat move to the right.
How to use directions to move your sprite
You can use two different methods to position and move your sprites. The first is to make your sprite "walk," and to change its direction when you want it to walk the other way.
Here are the five blocks you use to move your sprite in this way:
Move 10 Steps: This makes your sprite walk in the direction it is facing. If your sprite has been rotated, the steps taken could move your sprite in a diagonal line across the Stage. You can click the number in this block and then type another number to increase or decrease the number of steps taken.
Turn Right or Left 15 Degrees: This block rotates your sprite. You can edit the number to change the degree by which your sprite is rotated. Your sprite walks in the direction it is facing when you use the Move 10 Steps block.
Point in Direction 90: Whatever direction your sprite is facing, this block points it in the direction you want it to face. Use this block as-is to reset your sprite to face right. You can change the number in this block to change the direction you want your sprite to face and the numbers are measured in degrees from the position of facing up.
Think of it like the hands of a clock: When the hand is pointing right, it’s 90 degrees from the 12 o’clock position; when it’s pointing down, it’s 180 degrees from the top. To point left, you use –90. When you click the arrow in the right of the number box, it gives you a menu from which you can select four main directions, but you can enter any number.
You might be wondering whether you can enter 270 to point left, and the answer is that it works, but it can cause errors in your programs. If you turn your cat to direction 270 and then ask Scratch which way your cat is facing, it tells you –90. To avoid any inconsistencies like this, keep your direction numbers in the range –179 to 180.
Point Towards: You can also tell the sprite to point towards the mouse pointer or another sprite. Use the menu in this block to choose what you would like your sprite to point towards.
How to use grid coordinates to move and position your sprite
You can also move and position your sprite using grid coordinates. That makes it easy to position your sprite at an exact place on the screen, irrespective of where it currently is.
Every point on the Stage has two coordinates, an X position and a Y position. The X positions are numbered from -240 at the far left, to 240 at the far right. The Y positions are numbered from -180 at the bottom edge of the Stage, to 180 at the top edge.
That means the Stage is a total of 480 units wide and 360 units tall. The center point of the screen, where your cat begins his day, is where X equals 0 and Y equals 0.
When you move your mouse over the Stage, the grid reference of your mouse pointer is shown just underneath the Stage on the right.
Six Motion blocks use the X and Y coordinates:
Go to x:0 y:0: You can use this block to position your sprite at a specific point on the Stage. By default, it returns a sprite to the center of the screen (x=0, y=0). Edit the numbers for X and Y to position your sprite somewhere else.
Go to: Use this block to move your sprite to the mouse pointer’s location, or to the location of another sprite if you have more than one.
Glide 1 secs to x:0 y:0: When you use the Go To block, your sprite just jumps to its new position. The Glide block makes your sprite float there smoothly instead. You can change the number of seconds the glide takes, including using decimals for part of a second.
Change X by 10: This moves your sprite 10 units right. You can change the number of units and use a negative number if you want to move left instead. This doesn’t affect your sprite’s vertical position and is independent of which way around your sprite is facing.
Set X to 0: This changes the horizontal position of your sprite on the Stage, without affecting its vertical position. The value 0 returns it to the center of the screen horizontally, and you can edit the number to position it left or right of that. Use a negative number for the left half of the screen and a positive number for the right half.
Change Y by 10: This moves your sprite 10 units up the Stage, without affecting its horizontal position, and irrespective of which direction it is facing. You can change the number of units and use a negative number to move the sprite down the screen instead.
Set Y to 0: This changes the vertical position of your sprite on the Stage without affecting its horizontal position, and without regard to which way it faces. Use a positive value for the top half of the Stage and a negative value for the lower half.Credit: Scratch is developed by the Lifelong Kindergarten Group at the MIT Media Lab. See http://scratch.mit.edu