Skip to content

Please update your browser

Your browser version is not supported by this site. CS First may not work properly. Learn more

2. Make it Rain

Transcript

In this video, you will program the rain sprite to repeat moving from the top of the screen to the bottom.

This will make it look like it's raining in your story.

When you look at this example, it might appear as though there are thousands of little rain sprites, but it's actually one large rain sprite that scrolls from the top to the bottom of the stage and then repeats.

First, set a starting position for the rain.

From the motion menu, select a go to x y block.

Every position on the stage has an x and a y value.

X values determine left and right positions, and y values determine up and down positions.

To see the x and y numbers for any position on the stage, place a sprite on the stage, and read the x y coordinates shown below it.

A go to x y block sets the center of the sprite at the position you typed into the white value blanks.

For example, the top of the stage is y equals 180, so enter 180 for the y value and zero for the x.

This will make the sprite go up to the top of the stage and keep its left right position the exact middle of the stage.

When you click on this block to test it, you may notice that the rain sprite still takes up the entire stage.

That's because it's so huge.

You need to make the sprite start really far out, so it can glide down and look like rain is falling.

Drag out a glide block and attach it to the go to block.

It looks like the bottom of the stage is y equals negative 180.

This is where the middle of the sprite will move to when it glides.

Enter negative 180 into the y spot on the glide block.

Try it out.

Watch it glide by clicking on the block stack.

Great.

The rain sprite now starts at the top of the stage and scrolls down to the bottom.

Now you could duplicate this block stack a bunch of times to keep your rainy day going, or you can just program it to repeat.

From the control menu, drag out a forever block.

To tell the computer what action should be repeated, place the forever block around your block stack.

Now the computer will repeat these two blocks forever, or until you tell it to stop.

The sprite will go to the top of the stage, then glide to the bottom, then go to the top of the stage, then glide to the bottom, and so on.

Now it looks like it's raining in your story.

Tinker with the seconds value in the glide block to change the speed at which the rain is falling.

A longer amount of time will make the rain fall more slowly, and a smaller number will make the rain fall faster.

Finally, add a way for your audience to start this story.

Go to the events menu, choose a when flag clicked event, and place it at the top of this block stack so the story begins when the user clicks a flag.

Try it out.

Great.

Now it's your turn.

First, add a go to block and set the y value to 180.

Second, add a glide block and set the y value to negative 180.

Third, make the rain keeps falling with a forever loop.

And fourth, start the code with a when flag clicked block.

In the next step, you will program the lightning flash.

arrow_backward Back
Next arrow_forward
Instructions
  1. Set the starting position of the rain.
  2. Set where the rain will go to.
  3. Make the rain keep falling forever.
  4. Start the code when the green flag is clicked.