Keeping Track of Sprite Coordinates and Direction

Scratch provides three motion (reporter) blocks that can be used to retrieve and display information regarding the value of the sprite’s X- and Y-coordinates as well as the sprite’s direction. These code blocks are shown in Figure 5.9.

Figure 5.9. These code blocks provide the ability to retrieve and display a sprite’s coordinates and direction.


Note

Scratch’s stage coordinate system allows for a coordinate range of –240 to 240 on its X-axis and a coordinate range of 180 to –180 on its Y-axis.


To set up an example that demonstrates how to work with these reporter blocks, create a new Scratch application and add the following script to the default cat sprite.

When executed, this script will move the cat sprite around the stage to wherever the mouse-pointer is located, bouncing it off the edge of the stage when necessary. After adding the script, select each of the reporter blocks by clicking on the check box just to the left of each block in the blocks palette. Once you have done this, three monitors should be visible on the stage, as demonstrated in Figure 5.10.

Figure 5.10. Displaying a sprite’s coordinates and direction.


Once you have set up the application’s monitors, run the application, move the mouse-pointer around the stage, and keep an eye on the values reported by the monitors.

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

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