From Test-Scratch-Wiki

Touching Color ()?
2.0 Touching Color ().png
Category Sensing
Type Boolean

The Touching Color ()? block is a Sensing block and a Boolean block. The block checks if its sprite is touching the specified color. If the sprite is touching the color, the block returns "true"; triggering the rest of the script to continue. If it is not, it returns "false" the script remains neutral.

The color can be chosen by clicking on the block's color square, and then clicking anywhere in the Scratch project. For example, if the mouse was hovering over the color: blue and was clicked the color square would turn blue.

Example Uses

As this block detects if a color on its sprite is touching a color, it is widely used in collision detecting. Platformers often use this block.

Some common uses for the Touching Color ()? block:

  • Moving a sprite until it touches a color
repeat until <touching color [#000000]?>
    move (10) steps
  • Making a sprite do things if it touches a color

— for example, if the sprite touches blue (water), it reacts in a specific way

if <touching color [#0000FF]?> then
   say [I found water!] for (2) secs
  • Stopping bullets when they hit walls of a specific color
if <touching color [#ff0000]?> then
  • In a maze, sensing if a sprite has hit a dead-end
if <touching color [#007f00]?> then
say [Dead end!] for (1) secs
  • Making sprites not go through walls
if <touching color [#ffff7f]?> then
set [x velocity v] to (0)
  • Making Game End when touching color
if <touching color [#01efff]?> then
say [Game Over] for (1) secs
broadcast [Game Over v]

See Also

Cookies help us deliver our services. By using our services, you agree to our use of cookies.