In this Scratch tutorial, you'll learn the basics of programming with Scratch.
Blocks Covered
Motion Blocks
Move 10 steps
Turn 15 degrees
If on edge, bounce
Control Blocks
When green flag clicked
Forever
Definitions
Sprite
A character or object in Scratch that can be programmed to perform actions.
Motion
The movement of sprites on the Scratch stage, controlled by motion blocks.
Loop
A programming construct that repeats a set of instructions multiple times.
Event
A trigger that starts a script, such as clicking the green flag or a sprite.
Understanding Sprites
In Scratch, sprites are the characters or objects that perform actions in your projects. They're a fundamental part of any Scratch program. But what exactly is a sprite?
Definition: A sprite is any image that can move around and interact with other elements in your Scratch project. It could be a character, an object, or even just a simple shape.
The default sprite in Scratch is the cat, but you can create or choose many different sprites.
Adding a New Sprite
Figure 1: Adding a new sprite in Scratch
Here's how you can add a new sprite:
1
Look at the bottom right of the Scratch interface. Do you see a cat icon?
2
Click on the cat icon. What happens?
3
You should see a menu with different sprite options. Try selecting one!
Now that you've added a new sprite, take a moment to explore. Can you find where your new sprite appears in the Scratch interface? How many sprites can you add to your project?
Remember, each sprite can have its own set of instructions (or "scripts") that tell it how to behave. In the next exercises, we'll learn how to make our sprites move and interact!
Moving Sprites
Now that we understand what sprites are, let's make them move! In Scratch, we can use motion blocks to control how our sprites move around the stage.
One of the simplest ways to move a sprite is with the "move" block. It looks like this:
Figure 2: Move block in Scratch
This block moves the sprite 10 steps in whatever direction it's facing. But what exactly is a "step" in Scratch? How far do you think your sprite will move?
Let's Try It Out
Let's try it out:
1
Find the "move 10 steps" block in the Motion category (it's blue).
2
Drag it into the coding area.
3
Click on the block. What happens to your sprite?
Did the sprite move as far as you expected? Try clicking the block multiple times. What happens if you change the number 10 to a different number?
Now, let's make our sprite move automatically when we start our project. Can you think of a block we might use to start our project? Hint: It's green and has a flag on it!
Figure 3: When green flag clicked block in Scratch
Try connecting the "when green flag clicked" block to your "move" block. Then click the green flag above the stage. Does your sprite move automatically now?
Experiment with different numbers in the "move" block. Can you make your sprite move across the entire stage? What happens when it reaches the edge?
Changing Sprite Direction
Moving in a straight line is fun, but what if we want our sprite to change direction? In Scratch, we can use rotation blocks to make our sprites turn.
One of the blocks we can use is the "turn" block. It looks like this:
Figure 4: Turn block in Scratch
This block rotates the sprite clockwise by 15 degrees. But what does 15 degrees look like? How many degrees do you think it takes to make a complete circle?
Let's Experiment
Let's experiment:
1
Find the "turn 15 degrees" block in the Motion category.
2
Place it after your "move" block.
3
Click the green flag. What path does your sprite follow now?
Try changing the number of degrees. What happens if you use a negative number? Can you make your sprite move in a square path? A triangle?
Now, let's combine our movement and rotation to create a more complex pattern. Can you make your sprite move in a spiral path? Here's a hint: you might need to use more than one "move" and "turn" block.
Figure 5: The spiral path a sprite moves along
The sprite travels along this path but does not leave a line behind it, so the stage itself stays blank while it moves. Remember, in Scratch, you can always experiment and try new things. What other patterns can you create by combining movement and rotation?
Using Loops
So far, we've been making our sprites move by repeating blocks manually. But what if we want our sprite to keep moving or turning indefinitely? This is where loops come in handy!
In Scratch, one of the most common loops is the "forever" block. It looks like this:
Figure 6: Forever block in Scratch
The forever block repeats the blocks inside it... well, forever! Or at least until you stop the project. But how might this be useful? Let's find out!
Try This
Try this:
1
Find the "forever" block in the Control category (it's yellow).
2
Drag it under your "when green flag clicked" block.
3
Place your "move" and "turn" blocks inside the forever block.
4
Click the green flag. What happens now?
Your sprite should now move and turn continuously! But what if it goes off the screen? Can you think of a way to make it bounce off the edges?
Here's a hint: look for a block in the Motion category that mentions "edge". Can you add this block to your script to keep your sprite on the screen?
Figure 7: If on edge, bounce block in Scratch
Experiment with different combinations of blocks inside your forever loop. Can you make your sprite follow a continuous pattern? Or move in a figure-eight? Remember, in Scratch, there are many ways to achieve the same result - don't be afraid to try new things!
Homework and Exercises
Exercise 1: Race Two Sprites
Program your first sprite to move from one side of the backdrop to the other.
Add a second sprite to your project.
Program the second sprite to also move across the screen.
Experiment with different speeds to make one sprite faster than the other.
This exercise will help you practice using multiple sprites and controlling their movements independently.
Exercise 2: Dancing Cat
Use the blocks you've learned to animate the cat sprite. Combine different movements and rotations to create a dance-like animation. Be creative and see what interesting motions you can create!
This exercise encourages experimentation and helps you understand how different blocks interact to create complex behaviors.
Exercise 3: Treasure Hunt
Create a new backdrop with several "X" marks representing treasure.
Program your sprite to move to and "collect" each treasure.
Try to make the movement as efficient as possible.
This exercise combines everything you've learned about sprite movement and rotation, and introduces the concept of planning a sequence of actions to achieve a goal.