Time for action - a big step

We will continue working with our script from the previous example:

  1. From the blocks palette, select Motion.
  2. Drag the change x by block to the script area for Sprite1 and snap it in place at the end of the script. See the following screenshot for reference:
    Time for action - a big step
  3. Double-click on the script and watch your sprite move across the stage.

    Tip

    Double-clicking on the script runs through each block of the script.

  4. The change x by block has an number field with a default value of 10. This number controls how far the sprite moves. Change 10 to 20.
  5. Double-click on the script again.
  6. From the motion palette, drag the change y by block and add it to the end of your script.
  7. Change the value in the change y by block to a negative number, such as -30.
  8. Click the flag.
Time for action - a big step

What just happened?

We added the change x by block to our script to make the cat move horizontally toward the right side of the stage. As we increased the value, our sprite moved further across the stage each time.

Next, we added the change y by block and gave it a negative value. When we clicked the flag, the sprite continued to move horizontally to the right, but it also moved down.

Note

The numeric x or y values found on several of the motion blocks measure pixels. The stage is 480 pixels wide and 360 pixels tall.

Coordinating a sprite's location

Scratch uses an X and Y axis to divide the screen into quadrants. Enter a positive number for X, and the sprite moves to the right. Similarly, enter a negative number for X, and the sprite moves to the left, or backward. A positive Y value makes the sprite climb, while a negative Y value makes the sprite fall.

The unit of measure on our coordinate system is pixels. Each sprite on the stage has an X and Y coordinate that allows you to locate it, but it also allows you to send a sprite to a specific coordinate.

As we'll discover later, even the mouse pointer has an X and Y coordinate that allows us to precisely locate the pointer.

Double-click control

So far we've seen two ways to control the sprite on the stage. We can build a script that uses a control block, such as the flag. Or we can double-click on a block or set of blocks to run a command on the sprite.

The ability to run an individual block against a sprite gives us a chance to observe the behavior of the block before we add the block to our script. It's a great way to test and learn.

Double-clicking on a block works if we have one, ten, or an infinite number of blocks stacked together.

Pop quiz

  1. Double-clicking on a block or stack of blocks will run the script.
    • True
    • False
  2. If you tell your sprite to change x by -30 and change y by 10, which of the following statements best describes the motion of the sprite?
    • 30 pixels right, 10 pixels up
    • 30 pixels left, 10 pixels down
    • 10 pixels left, 30 pixels up
    • 30 pixels left, 10 pixels up
..................Content has been hidden....................

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