Scratch – Tutorial 09 – ‘Clone’ a sprite and create a scrolling game!

Scratch – Tutorial 09 – ‘Clone’ a sprite and create a scrolling game!

In this video we will be looking at the use
of ‘clones’ withing Scratch and I will show you how to create, duplicate and delete your
clones. This in turn will enable you to create a scrolling
game or a platformer. Welcome to another ‘Flipped’ Classroom Tutorials! First of all you’ll have to create a new game,
so go ahead and create a new file. Now for the sake of this Demonstration, I’m going
to leave our original ‘sprite’ on our canvas. I am going to create a second ‘sprite’. So
click on ‘Paint a new Sprite’. Go ahead and draw a Vertical line.
As you can see THIS is not straight but there’s a simple Quick trick and that’s to hold down
your SHIFT key as you draw. This drawing tool now snaps to horizontal
or vertical position. Go ahead and draw your line. Let’s re position this to line up with our
stage. I would like to have about 5 different costumes,
all with a line of a different height. So go ahead and right click. ‘Duplicate’ Costume 2 will be slightly smaller so we erase
the top of our line. And repeat the process until you have five
costumes. The reason I’m doing this is because I want
to create a scrolling game, where different heights of lines randomly appear on screen. And my character has to jump over them. So I now have 5 Costumes. Do note: These 5 costumes are ALL a part of
a SINGLE sprite. As we are going to work with clones: We are
NOT cloning the Costumes. We are cloning the SPRITE. Keep that in mind. Now go ahead and move your
character down so you can get a feel as to how he is going to jump. Now let’s go ahead and program our sprite.
My starting location of this Sprite (lines) will have to be at the bottom, which is y:
-180 and x: 240. Let’s go ahead and program this. Events –>When
the Green flag is clicked –>’go to x: 240 y:-180′. We want it to ‘glide’ to the other side of
the stage, this will have the same vertical y value and a different horizontal x value. x value will be -240 Go ahead and set your glide
to those coordinates. So it is now going to go to the starting position,
which is in the bottom right corner. And then glide to the left hand corner. Let’s test this and glide for about 5 seconds,
which won’t be too fast. And, try it out! As you can see, it glides across the bottom,
now this is a little bit too low so I’m going to change my y value and bring the sprite
UP a bit. Let’s bring it up to about 100 and see what
that looks like. Much better, as you can see it glides from
one side to the other. I could even move it up a little bit more,
so let’s go to -80, that looks better. Again, coding and Programming is ALL about
Debugging and trying out. There we go! I’m very happy with this! Even when I change costumes you can still
see the costume as it glides. Let’s set it to costume 1 and let’s start
programming the code we need for our ‘clones’. So, go ahead and select Control. Now what we are going to do is “create a clone
of ourselves”. When are we going to create this? Every 2
seconds. So when the green flag is clicked, Forever,
Create a clone of myself AND wait 2 seconds. So let’s test this! Let’s see what happens when we press the green
flag. We get a line, and every two seconds it creates a clone. These are spaced evenly, but the next thing
we want to do is tell it what to do as a ‘clone. So select ‘When I start as a clone’
Don’t just start where you were created, no, do the same thing as the original sprite and
go to x 240 y value – 80, glide for 5 seconds to the other corner. See what happens now. Have a clone created, a clone created and
created. As you can see they all remain on our stage.
So another little snippet of code we are going to add is glide for 5 sec and then DELETE
this clone. This will automatically delete our clone as
it finished gliding. Let’s see what happens. Press the green flag. Glides to the left –>Creates a second clone,
keep gliding and the clones get deleted. No I did forget to delete the original sprite. Because this is not a clone, we are gong to
use the ‘hide statement’. So ‘show’, ‘go to the coordinates’, ‘glide
5 seconds’ and then ‘hide’. Let’s see what happens. The same thing happens with our clones. Now very important, because we are showing
our sprite, going to a location, gliding to the left and then hiding it, we also have
to add a show statement to when I start as a clone. It slides or glides to the left, once it’s
done that it creates a clone, and that clone needs to be shown and does the same thing:
glides to the left and then deletes itself. slide to the left, create a clone, slide to
the left, and whenever it reaches the end it disappears. We are going to add some extra variation. Go ahead and select ‘switch to costume’ and
operators–>random 1 to 5 as we have 5 different costumes. When I start as a clone, switch to a random
selected costume and glide to the left. Let’s see what that looks like. Glide to the left, as you can see these are
now randomly selected, this in itself creates a challenging game. We can also speed it up
by changing the numbers. Don’t forget every change needs to be changed
at the clone too. What that looks like is THIS! You can also decrease the time it takes before
creating a clone. What I would suggest is play around with the
numbers. Create your own scrolling game! I hope this was helpful, if you want more
videos like this don’t forget to SUBSCRIBE, give my video a thumbs up and I will see you
in our next video! Thank you for watching.

6 thoughts on “Scratch – Tutorial 09 – ‘Clone’ a sprite and create a scrolling game!”

  1. When I right click it does not show delete or duplicate. I don't know what I'm doing wrong please help me.

Leave a Reply

Your email address will not be published. Required fields are marked *