- Hi everyone. It's Zoë from the Scratch Team, also known as Zinnea. Today, I wanted to show you how to make a mouse trail in Scratch. You can pick whatever items you want to be in the mouse trail, and I'll show you how to do
lots of different effects. Yeah, let's get started. So first, let's pick the object that you want to be in your mouse trail. You can hover over choose
a sprite and click choose. You could have a mouse
trail of scratch cats, or a mouse trail of hearts, or stars, or balloons, or rainbows, or, I don't know, the squirrel sprite? Really, anything you want. The first one I'll show is
a trail of Scratch cats. So to make a sprite
follow your mouse pointer, there's this block in the motion category that says go to random position, and if you click on the menu and choose mouse pointer, then whenever you click on this block, it makes the sprite go
to your mouse pointer. And if you put that block
inside a forever loop, then the sprite is always
going to your mouse pointer, so it's following your mouse wherever you go around the screen. Okay, so we have, not
exactly a mouse trail, but we have one sprite
following our mouse. Let's make this start when
the green flag is clicked. So when we click the green flag, the sprite is following our mouse. Now, how do we make it a trail so there's multiple Scratch cats following the mouse pointer? In scratch, you can create
duplicates of a sprite with this block in the control category, create clone of myself. So if I click on this, it creates a duplicate of the Scratch cat. So wherever I go, if I click create clone of myself, it makes another Scratch cat. And these clones don't
just have to sit there. You can make them do
things with code as well. And the way to do that
is, there's this block, when I start as a clone, if you drag out this block and put some code underneath it, the clones will do that
code when they're created, when they start as a clump. So for example, let's say when I start as a clone, change the color effect by 25. Okay, so we can make them change color. We could even make them do a repeat loop and change color a few times. So that will look like that and let's make it so that after they do their little color change, they disappear off the screen. So to do that we can add, delete this clone. So when I create a clone, it will do a little color
change and then be gone. So it's like the trail is always following where my mouse is and not staying too far
behind where it was. Now, how do we make it so that we're making
these clones constantly, as I'm dragging my mouse around? This is the part where it really starts to
feel like a mouse trail. You can put the create
clone of myself block inside the forever loop, and now you can drag the cat around and wherever it goes it creates a clone. So you get this effect where the cat is leaving
rainbow cats wherever it goes. Now, one important thing to note is, it's usually not a good idea to have a create clone of myself block
inside of a forever loop, because if a sprite
creates too many clones, it will make the computer run really slow. The reason it's okay here is
when a clone gets created, it does a little animation, but then it gets deleted. So we're never getting too many clones. So this base code will make a mouse trail. And the fun thing is, you can put all different kinds of things inside this repeat loop
and see what they do and you'll get different kinds of effects. So for example, you could
go to the motion category and put a change X by 10
block inside the repeat loop, and let's see what that does. So now the clones, when
they're getting created, what they're doing is
they're changing their color and then they're changing X by 10, so they're moving this way. We could also put in change Y by 10 and now they're changing their color and then they're going upward. Or if we wanted to have
a sort of falling effect, we can change Y by negative 10 and now the clones are, are going down. Also, here's one of my favorite effects. I like making the items in the mouse trail like spread out in every direction. So the way to do that is you can drag out this
point in direction block, which will make a sprite
point in a certain direction. And if you put in this pick random block and put in zero to 360, then it will point in a random direction from zero to 360 degrees. And if you do that, then if you click the move 10 steps block that makes a sprite go forward in whatever direction it's pointing. So, if you make the clones
pointing a random direction, and then inside the repeat loop, you put move 10 steps. Then before they start the repeat loop, they point somewhere random. And then they repeatedly move
in that direction 10 times. And that's how you can get this, like, I love this explosion effect. Also, if you ever want to switch what the object in your mouse trail is, you can just click on the costumes tab and pick a new costume. So I'll try something
else other than the cat. You could try putting in
a change size by block and put in a negative number, and then the items will
get smaller as they go out. I don't know what I'll try
negative eight or something. You would also, here's
another thing I love doing, if you want them to
fade as they go outward, you can put in a change
ghost effect block. If you change the ghost
effect of a sprite, it makes it get more transparent. So if I put that in here, okay, they fade really quickly. Let me change the ghost
effect by us small amount, like I'll just change the
ghost effect by five every time so they get a little bit more transparent. And there you go, now you have the objects
fading as they go out. You could also try, I don't know, putting in a turn block and see what that does. It makes the clones turn. See if you like that. Basically, I just recommend try any block and just put it in the repeat loop and see, see if you like what it does. Anyway, that's what I
wanted to show you today. I am so excited to see
all the mouse trails that people will make. If you want to use the code
from this starter project it'll be in the description below. And yeah, have fun making mouse trails. I'll see you next time and scratch on.