Time for action - spin sprite spin

  1. Let's get our sprites spinning.
  2. To start, click on Sprite1 from the sprites list. This will let us edit the script for Sprite1.
  3. From the Motion palette, drag the turn clockwise 15 degrees block into the script for Sprite1 and snap it in place after the if on edge, bounce block.
  4. Change the value on the turn block to 5.
    Time for action - spin sprite spinspritescreate new sprite option, using
  5. From the sprites list, click on Sprite2.
  6. From the Motion palette, drag the turn clockwise 15 degrees block into the scripts area.
  7. Find the repeat 10 block from the Control palette and snap it around the turn clockwise 15 degrees block.
  8. Wrap the script in the forever block.
  9. Place the when space key pressed block on top of the entire stack of blocks.
  10. From the Looks palette, snap the say hello for 2 secs block onto the bottom of the repeat block and above the forever block.
  11. Change the value on the repeat block to 100. Change the value on the turn clockwise 15 degrees block to 270. Change the value on the say block to I'm getting dizzy!
  12. Press the Space bar and watch the second sprite spin. Click the flag and set the second sprite on a trip around the stage.
Time for action - spin sprite spinspritescreate new sprite option, using

What just happened?

We have two sprites on the screen acting independently of each other. It seems simple enough, but let's step through our script.

Our cat got bored bouncing in a straight line across the stage, so we introduced some rotation. Now as the cat walked, it turned five degrees each time the blocks in the forever loop ran. This caused the cat to walk in an arc. As the cat bounced off the stage, it got a new trajectory.

We told Sprite2 to turn 270 degrees for 100 consecutive times. Then the sprite stopped for two seconds and displayed a message, "I'm getting dizzy!" Because the script was wrapped in a forever block, Sprite2 started tumbling again.

We used the space bar as the control to set Sprite2 in motion. However, you noticed that Sprite1 did not start until we clicked the flag. That's because we programmed Sprite1 to start when the flag was clicked.

Have a go hero

Make Sprite2 less spastic. Instead of turning 270 degrees, try a smaller value, such as 5.

Pop quiz

  1. Which of the following is a way to add a new sprite to our project?
    • Paint a new sprite
    • Get a surprise sprite
    • Choose a new sprite from file
    • All of the above
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.22.77.149