In this video, you will program your object to bounce around the screen.
This will create an unusual behavior for the object your characters discover.
To start, click the object sprite.
From the motion menu, click, hold and drag out a “glide random position” block.
When you click this block, the object glides for 1 second to a random spot on the stage.
Next, program the computer to repeat this action. Select the “Control” menu.
Click, hold, and drag out a “repeat” block. This block makes the code inside it run multiple
times. Place it around the block stack, and click to run.
To make the sprite bounce faster and longer, tinker with the values in the glide block
and the repeat loop. This example uses zero point 5 in the glide block, so the object
glides to a random location ten times really fast!
There’s a bug, or error, in this code though. After the repeat loop finishes running the
code, the object is stuck in a random place on the stage. To fix this, use a “go to
x y” block. This block makes the sprite go to a specific
position. When you drag it out, the values are set to the current position of the sprite.
Drag the sprite to where you want it to be on the stage after it finishes bouncing.
Then, click the motion menu and add a “go to x y” block to the bottom of this code stack.
Click the code stack to test this. Great. Feel free to make your object move to a special
place in your program to help tell your story. Finally, program this block to run when the
sprite is clicked. From Events, add a “when this sprite clicked” block. Try it out!
Add “say” blocks to your character sprites to tell your audience to click the object
to see what it does. This helps your audience feel like they are part of your story.
Now, it’s your turn! Select the object sprite.
Add a “glide random” block and a “repeat” loop.
Add a “go to x y” block to make the sprite move to a specific position when it stops
bouncing. Add an event, like “when this sprite clicked.”
Then, return to this page to select another video to try.