You are going to learn how to program your own animation!
Step 1: Animating a spaceship
Let’s make a spaceship that flies towards the Earth!
Start a new Scratch project by clicking File then New form the menu bar, and delete the cat sprite so that your project is empty.
Your club leader should have provided you with a resources folder containing the sprites that you’ll need for this project. Ask your club leader for help if you can’t find them.
Add a new sprite to your stage by selecting the ‘Choose new sprite from file’ button beneath the stage:
Go to the resources folder and select ‘Spaceship’.
Add a second sprite named ‘Earth’.
Import a stars background by selecting the stage then clicking ‘Import’ from the ‘Backgrounds’ tab.
Your stage should look like this:
Double-click on the spaceship sprite to bring up the Paint Editor.
Click the ‘rotate clockwise’ button until the spaceship is on its side.
Add this code to your spaceship sprite:
Change the numbers in the code blocks, so that the code is exactly the same as in the image above.
If you click on the code blocks to run the code, you should see the spaceship speak, turn and move towards the centre of the stage.
The screen position
x:(0) y:(0)is the centre of the stage. A position like
x:(-150) y:(-150)is towards the bottom-left of the stage, and a position like
x:(150) y:(150)is near the top-right.
If you need to know the coordinates of a position on the stage, move the mouse to the position you want and make a note of the coordinates, which are displayed below the stage.
Try out your animation, by clicking on the green flag just above the stage.
Challenge: Improving your animation
Can you change the numbers in your animation code, so that:
- The spaceship moves until it touches the Earth?
- The spaceship moves more slowly towards the Earth?
You’ll need to change the numbers in this block:
glide (1) secs to x:(0) y:(0)
Save your project
Step 2: Animating using loops
Another way of animating the spaceship is to tell it to move a small amount, lots of times.
glideblock from your code, by dragging it off the script area, back into the code blocks area.
Once you’ve removed your code, add this code instead:
repeatblock is used to repeat something lots of times, and is also known as a loop.
If you click the flag to try out this new code, you’ll see that it does pretty much the same thing as before.
You can add more code to your loop, to do interesting things. Add the
change color effect by 25block into the loop (from the ‘Looks’ section), to repeatedly change the colour of the spaceship as it moves:
Click the flag to see your new animation.
You can also make your spaceship get smaller as it moves towards the Earth.
Test out your animation. What happens if you click the flag a second time? Does your spaceship start off the right size? Can you use this block to fix your animation:
set size to (100) %
Save your project
Step 3: Floating Monkey
Let’s add monkey to your animation, who’s lost in space!
Start by adding in the monkey sprite from the library.
If you click on your new monkey sprite and then click ‘Costumes’, you can edit how the monkey looks via the ‘Edit’ button. Click the ‘Ellipse’ tool, and draw a space helmet around the monkey’s head.
Now click ‘Scripts’, and add this code to the monkey, so that it spins slowly in a circle forever:
foreverblock is another loop, but this time one that never ends.
Click the flag to test your monkey. You’ll have to click the stop button (next to the flag) to end this animation.
Step 4: Bouncing Asteroids
Let’s add some floating space-rock to your animation.
Add a ‘rock’ sprite to your animation.
Add this code to your rock, to make it bounce around the stage:
Click the flag to test your rock. Does it bounce around the stage?
Step 5: Shining Stars
Let’s combine loops to make a shining star.
Add a ‘star’ sprite to your animation
Add this code to your star:
Click the flag to test out this star animation. What does this code do? Well, the star is made slightly bigger 20 times, and then made slightly smaller 20 times, back to its original size. These 2 loops are inside a
foreverloop, so the animation keeps repeating.
Save your project
Challenge: Make your own animation
Stop your space animation, and click ‘File’ and then ‘New’, to start a new project.
Use what you’ve learnt in this project to make your own animation. It can be anything you like, but try to make your animation match the setting. Here are some examples: