From Test-Scratch-Wiki

颜色 () 碰到颜色 ()?
顏色 [#ea235c] 碰到顏色 [#cba81a] ?
类别 侦测类积木
形狀 菱形积木

The Color () is Touching ()? 积木 is a 侦测类积木 block and a 菱形积木. The block checks if a color on its 角色 is touching another color; if the color on its sprite is touching the color, the block returns true; if it is not, it returns false.

The color in a color square can be chosen by clicking on the color square and then clicking anywhere in the Scratch editor.

The block as seen in Scratch 1.2

In versions of Scratch before 1.2, this block was called Color () is Over ()?.

用法示例

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

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

  • Moving a sprite until a color on its sprite touches a color
重複直到 <顏色 [#ea235c] 碰到顏色 [#cba81a] ?> 
  面朝 [Sprite2 v] 向
  移動 (10) 點
end
  • Making a sprite do things if a part of a sprite touches a color; for example, if the sprite's mouth touches blue (water), it drinks some water
重複無限次 
  如果 <顏色 [#ffffff] 碰到顏色 [#0000ff] ?> 那麼 
    造型換成 [drinking water v]
    等待 (1) 秒
    造型換成 [not drinking water v]
  end
end
  • Stopping bullets when they hit walls of a specific color
重複無限次 
  如果 <顏色 [#ffd700] 碰到顏色 [#f321a5] ?> 那麼 
    隱藏
  end
end
  • In a maze, sensing if a sprite has hit a dead-end
重複無限次 
  如果 <顏色 [#000000] 碰到顏色 [#007f00] ?> 那麼 
    說出 [Uh-oh, I hit a dead end!] (2) 秒
  end
end

参见

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