Repositioning a Sprite

Scratch provides access to three motion blocks that move a sprite to a specified coordination location on the stage, move a sprite to the location currently occupied by the mouse-pointer or another sprite, or move a sprite to a specified coordination position over a specified number of seconds. These code blocks are shown in Figure 5.6.

Figure 5.6. These code blocks can be used to move a sprite to a specific location.


The first of these three motion blocks allows you to reposition a sprite to any location on the stage by specifying X-axis and Y-axis coordinates for the sprite. For example, the following script demonstrates how to reposition a sprite in the middle of the stage, pointing it in a 90-degree direction.

The following script demonstrates how to move a sprite to the location on the stage currently occupied by the mouse-pointer.

Figure 5.7 shows an example of the output that is generated when this script is run. If you look closely, you will see that in each of the three examples, the cat sprite remains positioned directly under the mouse-pointer no matter where it is moved on the stage.

Figure 5.7. As this figure demonstrates, the sprite automatically moves around the stage, following the mouse-pointer.


This next script demonstrates how to reposition a sprite to a specific location on the stage. Instead of simply making the sprite appear at a specified location, as demonstrated in the previous two examples, this script repositions the sprite by moving or gliding to its new position in a smooth motion.

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

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