In many instances, such as game development or animation, it can be helpful to have objects falling from the sky. Follow the steps below to complete this fun and useful project!
To begin, create a new project as explained above in Scratch. Delete the cat sprite that loads in by default and choose the sprite that you would like to fall from the sky. We also
recommend selecting a background, but it’s not mandatory for this project. (For our project, we chose “star” as our sprite and “galaxy” as our background).
Next, we will use the clone feature to create infinite copies of our original sprite. We can do so with the code above. Let’s see how it works:
-
When “green flag” clicked: This block will cause the blocks below to run when the green flag is clicked.
-
Hide: Although we want our original sprite to exist so that it can be cloned, we don’t actually want it to be visible.
Without this hide block, our original sprite would stand still in the middle of our project. By hiding it, we are still able to clone it, but it is not visible.
-
Forever: This creates a loop that will run forever. This suits our needs, because we want our sprites to fall forever
(or, at least until the stop sign is clicked to end the program).
-
Wait .1 seconds: This block controls how often a new sprite appears on the screen. The .1 value can be increased or
decreased to control the quantity of sprites; a value of 0 will create many sprites, while a value of 1 will create occasional sprites.
-
Create a clone of myself: This block tells the program to create a copy of the original sprite.
For the next step, we will need a new variable called “x value.” Create this variable as in the previous project. Once you’ve created the variable, you can uncheck the box to hide it from the
project.
With the variable created, we can add the final set of code to our program:
-
When I start as a clone: This block makes it so that the following blocks will run every time a new clone is created.
-
Set x value to (pick random -240 to 240): Sprite placement in the Scratch canvas is controlled by an invisible grid, and
you can place things around the grid by giving them an x value and a y value. The x value controls placement left to right, and the y value controls placement up and down. X values can range
from -240 to 240; the closer to -240, the further left, and the closer to 240, the further right. Y values range from -180 to 180, with -180 being at the bottom of the screen and 180 being at
the top. All that said, this block of code randomly chooses and stores an x value that will be somewhere between the left and right of the screen.
-
Go to x: x value y: 180: This block of code moves our clone to the appropriate location. The x value was determined in
the previous step, and the y value is set to 180 so the clone will appear at the top of the screen.
-
Show: As you’ll remember, in the previous code we set up, we made our original sprite invisible with a “hide” block. If
we want our new clones to be visible, we will have to make them appear with a “show” block.
-
Glide (3) secs to x: x value y: -180: The glide block will make our clone glide across the screen to a specified
location. You can increase or decrease the number of seconds to make the clones fall more slowly or more quickly. Since our clone will be falling straight down, we can use the same x value as
before. You can change the y value depending on how far down you want the clones to fall, but we have found -180 to work well.
-
Delete this clone: This block of code deletes the clone once it reaches the bottom of the screen.
Source: https://www.create-learn.us