Time for action - stay dog

In this exercise, we're going to start the scene by positioning the dog in front of the microphone and end the scene by lying the dog on its side.

  1. Find the dog's current X and Y coordinates by looking in the Sprite Info section. Just above the Scripts, Costumes, and Sounds tabs, the sprite's current location displays.
    Time for action - stay dog
  2. From the Motion palette, drag the set x to 0 block to the scripts area. Change the input value to the dog's X value. My example uses -56.
  3. Add the set y to 0 block.
  4. Change the input value to the dog's Y value. My example uses -116.
  5. Let's identify some coordinates in front of the dresser. As you move your mouse around the stage, Scratch tracks the X and Y position of the mouse. The information is displayed as x and y values in the space between the stage and the sprites list.
    Time for action - stay dog
  6. From the Motion palette, add the glide 1 secs to x: -56 y: -116 block to the scripts area, but do not attach it to the previous blocks.

    Note

    Note that the glide block is populated with the current x and y coordinates of the selected sprite.

  7. Change the x value on the glide block to 152.
  8. Change the y value on the glide block to -47.
  9. Change the secs value on the glide block to 2.

    Tip

    The more seconds you add, the longer it takes the dog to reach its coordinates.

  10. Run each script by double-clicking on it and observe how the dog changes its positions.
Time for action - stay dog

What just happened?

We issued a series of commands, and our dog responded with precision. The first command sets the dog's X and Y position next to the microphone. The second command moves the dog to the new X and Y coordinates in front of the dresser. The 2 seconds we specified in the glide block means the dog takes 2 seconds to reach the new coordinates. If we wanted the sprite to amble along, we could set a higher value, such as 10 seconds.

When we built the horse scene, we didn't need to know the position of the horse because it didn't move. Each time we displayed the horse, it was in the same location.

However, the dog changes position as the scene plays out, and since Scratch remembers the sprite's previous position, we need to ensure that the dog always starts in front of the microphone when the scene starts.

Position on the grid

The X axis divides the stage into equal halves horizontally, and the Y axis divides the stage into equal halves vertically. The two axes intersect in the middle of the screen or at coordinates (0,0).

If a sprite has a positive X value, it's positioned in the right half of the stage. If a sprite has a positive Y value, it's positioned in the top half of the stage. A negative X value can be found in the left half of the stage, and a negative Y value can be found in the bottom half of the stage.

The following table defines several key locations on the stage. The coordinates are listed in the format (X,Y):

Coordinate

Description

More Information

(0,0)

Marks the center of the stage.

To set a sprite in the middle of the stage horizontally, specify X:0. To set a sprite in the middle vertically, specify Y:0.

(240,0)

Marks right edge of the stage.

Specify a Y value to move up or down the right edge.

(-240,0)

Marks the left edge of the stage.

Specify a Y value to move up or down the left edge.

(0,180)

Marks the top edge of the stage.

Specify an X value to move right or left across the top edge.

(0,-180)

Marks the bottom edge of the stage.

Specify an X value to move right or left across the bottom edge.

The following screenshot shows the Scratch stage with an (X,Y) grid as a background. This grid is one of Scratch's included backgrounds.

Position on the grid

Pop quiz

  1. What is the significance of the say for block?
    • You can specify how long the speech bubble displays.
    • The script stops for the time specified.
    • All of the above.
  2. What point on the Scratch stage do the coordinates -240,-180 represent?
    • Center stage.
    • Bottom-left of the stage.
    • Top-right of the stage.

Pointed in the right direction

Most dogs don't walk across the room backwards like ours does. Let's get our dog to walk forward.

..................Content has been hidden....................

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