Determining Distance

Rather than detecting when one sprite collides with another sprite, you may want to detect when one sprite comes within a certain distance of another sprite or the mouse-pointer. You can do this using the sensing code block shown in Figure 6.10.

Figure 6.10. This sensing block reports on a sprite’s distance from a specified object.


To develop an understanding of how to work with this code block, modify the previous Scratch application, replacing the dragon sprite’s script with the script shown here.

One you have replaced the script, run the application and then move the mouse-pointer around the stage. When you do, the dragon sprite will follow, and whenever it moves within 150 steps of the red rectangle sprite, an audio file will be repeatedly played.

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

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