4.1.1 Touching block

View

The Touching block is a combination of a sensing block and a Boolean block. The touching block checks if its sprite is touching the mouse-pointer, edge, or another sprite (a reporter block that returns the sprite's name, usually a variable can be used). If the sprite is touching the selected object, the block returns true; if it is not, it returns false.

The following picture shows the script of how a sprite can report back (saying that it touched an edge) when the sensing statement is true (touching an edge).

 

Figure 102: Sprite touching the edge

With a sensing block, you can build a script that makes a sprite respond when it is touching another sprite, the mouse position/ pointer? Or the edge of the stage and then report to anything you added on the script.

 

Example

The example below shows what a sprite can do when touching a mouse pointer:

  • Write the Scratch programme as seen in the figure.
  • Put the mouse pointer in the direction of the sprite.
  • Click on space to start the script and observe what happens when it touches the mouse pointer. 

 

Figure 103: Sprite touching a mouse pointer

 

The sprite can also sense a colour.  The block checks whether its sprite is touching an object with a specified colour and responds by using the following statement.

 

  .

 

Example: this script is showing how a sprite responds when it touches a black object

 

Figure 104: Script in which sprite responds when it touches a black object

The colour of a sprite can also sense another colour by using this blockThis block checks whether the first input, a colour on its sprite, is touching another colour. If it is, the block reports true, and if not, it reports false. Both colours need to be the same for the sprite to return true!

The example below shows what a sprite can do when touching a particular colour.  If the script touches the colour red it will go to position x:5, y: -31

 

Figure 105: Script and results when a sprite touches the 5X and -31Y

Last modified: Wednesday, 29 September 2021, 4:30 PM