Working with Sensing Code Blocks

An important capability needed by a graphical programming language that works with sprites is the ability to determine when certain things happen. For example, sprite-based applications typically need to know when sprites collide with one another or when the user presses certain keystrokes. This type of functionality is provided in Scratch by sensing blocks.

Sensing blocks also provide the ability to determine the location of the mouse-pointer and the ability to determine a sprite’s distance from other sprites. Sensing blocks are colored sky blue. In total, Scratch provides access to 15 different sensing blocks, which you can work with by clicking on the Sensing button located at the top of the blocks palette.

Scratch organizes sensing blocks into eight sub-groupings, each of which is separated by a blank space in the blocks palette. These sub-groupings include:

  • Sensing blocks that retrieve and report on the left mouse button status and mouse-pointer coordinates.

  • A sensing block that determines when specified keyboard keys have been pressed.

  • Sensing blocks that determine if a sprite has made contact with the mouse-pointer, another sprite, or the edge of the stage.

  • A sensing block that reports on a sprite’s distance from the mouse-pointer or another sprite.

  • Sensing blocks that provide access to a built-in timer that can be used to control the timing of application activity.

  • A sensing block that retrieves a property value (X position, Y position, direction, costume number, size, or volume) for the stage or a specified sprite.

  • Sensing blocks that report on how loud audio input coming from the computer’s microphone is.

  • Sensing blocks that work with a Scratch Board, allowing you to create applications that can detect changes in light and sound and work with the Scratch Board’s buttons and slider control.

Except for the reset timer code block, all sensing code blocks are reporter blocks, designed to be embedded inside stack blocks. Examples of how to work with each of the sensing code blocks listed above are provided throughout the rest of this chapter.

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

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