How to Move a Sprite in Scratch on the Raspberry Pi

By Richard Wentk

In Scratch on your Raspberry Pi, the stage has characters called sprites, which can move around the stage, bump off the walls and off each other, and do all kinds of other stuff.

To move a sprite using go to:

  1. If you can’t see the blue blocks in the block list, click the blue Motion button near the top left of the screen.

  2. Look down the list to find the block called go to x: y:.

    When you click it or include it in a script, it sets the x and y numbers that move a sprite. If you haven’t changed anything, the numbers are both 0, so the block looks like this:

    go to x:0 y:0

    You can see the x and y numbers in the block.

  3. Double-click the x: number, and when it turns gray, type 200 and press Enter.

    With a new x number, the sprite jumps toward the right of the screen. Cool! See how it works?

  4. Now double-click the y: number, and when it turns gray, type –100.

    The sprite moves down. The following figure shows where it ends up.

    image0.jpg

Your sprite may not be in the same place. The width and height of the stage depend on the width and height of your screen (monitor), so your stage may not be the same width and height as the stage in the image. You don’t need to worry about where the sprite is, as long as it moves!

How to center a sprite

Can you work out how to use a go to block to move a sprite to the middle of the stage?

You can probably guess that if you change x and y to 0, the sprite will jump back to the middle.

Now you can play with typing other numbers into the x and y boxes to see what they do. After a while, you should be able to guess what a number does before you try it.

If you look at the block list, you can see other blocks you can use now. Click once on the following to see what they do:

change x by [number]
set x to [number]
change y by [number]
     set y to [number]

How to glide a sprite

People and things in the real world don’t usually jump instantly from one place to another. To make movement look more ­realistic, you can use the glide block.

The glide block works like the go to block, but it has an extra number, which sets how long it takes the sprite to glide from one place to another.

Try changing the x and y numbers and the time in seconds in the glide block to see what it does.

How to move and turn a sprite

Scratch gives you another way to move sprites. Instead of moving to somewhere on the stage, you can tell a sprite to move in the direction it’s facing. You can also turn it to make it face in a different direction.

Use the move, turn, and point blocks to move like this. They’re at the top of the block list. Try clicking on them and changing the numbers in them to see what they do.

There’s also a point in direction block that makes the sprite turn to face the direction you set. The direction is set in degrees, which are like small turning steps. So 360 degrees turns the sprite all the way around, which is kind of pointless. And 180 degrees turns it halfway around, while 90 degrees turns it a quarter of the way around.

You can click the number box to set your own number, or you can select four directions from a menu. See whether you can work out which numbers mean left, right, up, and down.

If you turn a sprite, it may not turn on the stage, even though it’s pointing in a new direction. This may be confusing, because although the sprite has turned because you told it to, it still looks like it’s facing that way!

The complicated mathy word for turning something is rotation. Scratch gives you a choice about how the sprite looks when you rotate it.

If you look closely, you can find three tiny buttons to the left of the sprite in the top part of the middle window.

You can click any button to select it. From top to bottom, they work like this:

  • can rotate: Click this button to make sure the sprite always turns. It can face up, down, left, right, or any direction in between. Sometimes this means it’s upside down.

  • only face left/right: The sprite faces only left or right, even if it’s pointing up or down. It’s never upside down.

  • don’t rotate: The sprite always faces the same way. You can still change its direction, but you only ever see one direction on the stage.