Skip to content

Please update your browser

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

4. Gli sprite animati


In this video, you will learn how to use the “pick random” block to make your clones’ movement unexpected and interesting. Click on the operators menu, and drag the "pick random" block into the value area of the "wait" block.

The “pick random” block chooses a random number between these two values each time it runs. With the “pick random” block inside the “wait” block, the computer might wait 1 second, then 5 seconds... it will choose a random wait period every time.

With the "pick random" block added, the flying clones do not fly onto the screen over and over again at the same pace. Remember, you can always experiment with these values.

Now that you’ve randomized how long the computer waits between creating clones, randomize where the clones start and glide.

Start the sprite at a random height by adding another "pick random" block to the "go to" block's y value. Set the values to negative 180 and 180 to represent the top and bottom of the screen. To make the sprite glide to random height, add another "pick random" block with the same values to the “glide” block.

Test this out. The clones should now start and end at random heights.

You can further experiment with random values by making the clones glide at different speeds.

Add a "pick random" block to the seconds value in the “glide” block.

The size of the clone can also be randomly generated. Click on the "looks" menu, drag out a "set size to 100%" block, and add it to the top of the "when I start as clone" stack. 100% is the original size. A value smaller than 100%, will make the clone smaller. To randomly select a value for the “set size to” block, add a "pick random" block. Choose the smallest and largest percent values you want the clones to be. Great!

Test your code. Now, the window is filled with many clones of the flying sprite, and each clone has its own randomly selected size, speed, and behavior.

By cloning these sprites, you've created many objects, each with its own attributes like size, and its own behavior, like gliding speed. Lastly, place the storefront sprite in front of your other sprites. To do this, click on the storefront, and the looks menu. Drag out a "go to front" block, and place a “when flag clicked” event above it. Click the flag. Since the storefront window is transparent, you'll see the flying sprites.

Scratch is more than just a programming language. It’s a community of like-minded users who share projects, inspiration, and encouragement. Join in by filling out your profile page with what you like to do and what you’re working on in Scratch. Never share personal information, like your home address or last name, on Scratch or any internet site.

Now, it's your turn: Add "pick random" blocks to the y values of your “go-to” and “glide” blocks. Add a "set size to" block with a "pick random" block to randomly change the size of the sprite Then, add a "go to front" block and a “when flag clicked” event to the storefront sprite to make your clones show through the store window.

arrow_backward Indietro
Avanti arrow_forward
  1. Fai avviare i cloni dello sprite a intervalli e altezze casuali.
  2. Fai scivolare i cloni ad altezze e velocità casuali.
  3. I cloni devono avere dimensioni casuali.
  4. Fai apparire lo sprite Vetrina davanti agli altri sprite.