IAN LANG ELECTRONICS

Making sure your selector is highlighted, click on the ellipse you've just drawn and a box will appear around it like this:

Back to Title

Making Two Sprites Move Together

Previous Page

The eight squares at the corners and line centres are handles and they allow you to size and shape the elipse. The round dot in the centre is also a handle and allows you to position it. Put it as close to the centre of the window as you can. The round dot  sticking out at the top allows you to rotate it; we shan't need to do that here, but play about with these. Watch what happens in your viewer window; you'll probably end up with something like this:

In your viewer window just move the ellipse down over the cat's feet. It will cover them like this:

z - order and what this means is that it stacks them in layers, one above the other. The shadow should be under the cat's feet but because it was drawn in after the cat was placed Scratch thinks it should be on top. Scratch does not know it's meant to be a shadow and so it treats it ust like it would any other graphic and stacks it on top of the cat. It's an easy fix to do and we do it by means of a flowblock. Here it is:

Step by step:

Go out of the costume tab and into the scripts tab.

Make sure the ellipse is still selected.

In the scripts tab go to Looks.

Click on Go back 1 layers once or twice as needed until the ellipse goes behind the cat.

That's it.

Now, in the top right hand corner you will find the x and y co-ordinates of the ellipse (it does this for whatever selected sprite) and they look like this:

The x co-ordinate there (how far along the screen it is) is  -77 and the y co-ordinate(how far up and down)  is -93 and make a note of the y co-ordinate you have because you will need it when it comes to the code. Remember this is for the ellipse, not the cat. The sign is important. It will either be a minus or no sign at all. 0,0 is the dead centre of the viewer and the more minus the y co-ordinate, the lower down from the centre. The more plus the y, the further up from the centre. With x minus is left and plus is right.

Before we can code the shadow we now have to make a variable. So select either the cat or ellipse, doesn't matter which, and go to the data section of the scripts window and click Make a Variable. When the dialogue box comes up, fill it in like this:

If the cat is not selected already select it and add a new flowblock in like this:

Construct the block as highlighted left and slip it in to the flow as shown by the red arrow above.

And finally, code up for the ellipse:

Now click the green flag, press the space bar and watch the cat walk and the shadow follow.

What's happening here is the event space bar pressed is working on both sprites at the same time.

Notice how the cat's x position (how far left or right he is) is always reported to the variable catpos. The ellipse is always told to go to catpos on the x co-ordinate but always told to go to the same co-ordinate on the y position  which is  -93  and that's why we needed to know that figure. So it moves to the same x co-ordinate as the cat but never deviates in y  -  the practical upshot is that it looks like a shadow following the cat.

If you've got here have a cup of tea. You've earned it. The next lesson is a bit easier. The one after that is a pig in lipstick - you'll need a pint mug at least.

Next Lesson >