Lost in Space
Lost in Space
Lost in space
Learn how to program your own animation!
Step 1 Introduction
Your first step will be to create a spaceship that flies towards the Earth!
You can search for a sprite, or browse for one by category. Click on a sprite to add it to your project.
Add the ‘Stars’ backdrop to your Stage.
Use the arrow tool to click and drag a box around the whole spaceship image. Then click on the circular
rotate handle, and rotate the image until it is on its side.
Add this code to your spaceship sprite:
when clicked
point in direction 0
go to x: -150 y: -150
glide 1 secs to x: 0 y: 0
Change the numbers in the code blocks you’ve added so that the code is exactly the same as above.
If you click the green flag, you should see the spaceship speak, turn, and glide towards the centre of the stage.
Challenge!
glide 1 secs to x: 0 y: 0
Scratch coordinates
Scratch coordinates
In Scratch, the coordinates x:0, y:0 mark the central position on the Stage.
A position like x:-200, y:-100 is towards the bottom left on the Stage, and a position like x:200, y:100 is
near the top right.
You can see this for yourself by adding the Xy-grid backdrop to your project.
Step 3 Animation using loops
Another way to animate the spaceship is to tell it to move a small amount many times
Delete the glide block from your code. To do this, drag the block off the Code area and drop it back
where the other single code blocks are.
when clicked
point in direction 0
go to x: -150 y: -150
glide 1 secs to x: 0 y: 0
Now use a repeat block to move your spaceship towards the Earth.
when clicked
point in direction 0
go to x: -150 y: -150
repeat 200
move 2 steps
Test and save your code. Your spaceship should move towards the Earth exactly as before, but this time
it uses a repeat block.
Next add code to your spaceship sprite so that the spaceship changes colour as it moves towards
Earth?
Use this block:
when clicked
point in direction 0
go to x: -150 y: -150
repeat 200
move 2 steps
I need a hint
Your code should look like this:
when clicked
point in direction 0
go to x: -150 y: -150
repeat 200
move 2 steps
Test and save your code. Your spaceship should now get smaller as it moves. Test your spaceship a second time.
Is it the right size when it starts?
Step 4 Floating monkey
Now you will add a monkey who’s lost in space to your animation!
Click on your new monkey sprite and then click on Costumes so that you can edit how the monkey looks.
Set the fill to be transparent by selecting the red line. For the outline, set a white colour by moving the
Saturation slider to 0.
Click on the circle tool and then use it to draw a white space helmet around the monkey’s head.
Can you add code to your monkey sprite so that it spins slowly in a circle forever?
I need a hint
Here’s the code to make your monkey spin:
when clicked
forever
turn 1 degrees
Test and save your project. You’ll have to click on the red stop button to end this animation, as it runs forever!
Step 5 Bouncing asteroid
I need a hint
Here’s the code for making your rock bounce around the stage:
when clicked
forever
move 2 steps
if on edge, bounce
Step 6 Shining star
I need a hint
Here’s the code to make your star grow and shrink:
when clicked
forever
repeat 20
change size by 2
repeat 20
change size by -2
Challenge!