From Test-Scratch-Wiki

碰到顏色 ()?
碰到顏色 [#000000] ?
類別 偵測類積木
形狀 菱形積木

The Touching Color ()? 積木 is a 偵測類積木 block and a 菱形積木. The block checks if its 角色 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 專案. For example, if the mouse was hovering over the color: blue and was clicked the color square would turn blue.

用法示例

As this block detects if a color on its sprite is touching a color, it is widely used in collision detecting. 遊戲平台s often use this block.

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

  • Moving a sprite until it touches a color
重複直到 <碰到顏色 [#000000] ?> 
  移動 (10) 點
end
  • Making a sprite do things if it touches a color

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

如果 <碰到顏色 [#0000FF] ?> 那麼 
  說出 [I found water!] (2) 秒
end
  • Stopping bullets when they hit walls of a specific color
重複無限次 
  如果 <碰到顏色 [#ff0000] ?> 那麼 
    隱藏
  end
end
  • In a maze, sensing if a sprite has hit a dead-end
重複無限次 
  如果 <碰到顏色 [#007f00] ?> 那麼 
    說出 [Dead end!] (1) 秒
  end
end
  • Making sprites not go through walls
重複無限次 
  如果 <碰到顏色 [#ffff7f] ?> 那麼 
    變數 [x velocity v] 設為 (0)
  end
end
  • Making Game End when touching color
重複無限次 
  如果 <碰到顏色 [#01efff] ?> 那麼 
    說出 [Game Over] (1) 秒
    廣播訊息 [Game Over v]
  end
end

參見

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