From Test-Scratch-Wiki

"Touching" redirects here. For the block that senses if a sprite is touching a color, see Touching Color ()? (block).
碰到 ()?
碰到 [邊緣 v] ?
类别 侦测类积木
形狀 菱形积木

碰到 ()? 积木 is a 侦测类积木 and a 菱形积木. The block checks if its 角色 is touching the 滑鼠游标, edge, or another sprite (a 椭圆形积木 holding the sprite's name can be used). If the sprite is touching the selected object, the block returns true; if it is not, it returns false.

This block behaves differently when the sprite is 隐藏. Every check for collisions with other sprites return false, however it still senses the mouse and the edges.


As the block checks if its sprite is touching an object, it is widely used in detecting collisions.

Some common uses for the 碰到 ()? block:

  • Moving a sprite until it touches the edge of the screen
重複直到 <碰到 [邊緣 v] ?> 
  移動 (3) 點
  • Having a sprite chase another sprite until the chaser touches the runner
重複直到 <碰到 [角色2 v] ?> 
  面朝 [角色2 v] 向
  移動 (3) 點
說出 [I caught you!] (2) 秒
  • Stopping bullets when they hit walls
如果 <碰到 [wall v] ?> 那麼 
  • In a maze, sensing if a sprite has hit a dead-end
  如果 <碰到 [maze walls v] ?> 那麼 
    說出 [Dead end!] (1) 秒
  • Checking if a sprite is touching the mouse pointer
當 @greenflag 被點擊
  如果 <碰到 [滑鼠游標 v] ?> 那麼 
    造型換成 [highlighted v]
    造型換成 [normal v]
  • Checking if the player has touched an enemy in a game
  如果 <碰到 [Enemy v] ?> 那麼 
    說出 [Game over!]
    停止 [全部 v]

Related Suggestion

Some Scratchers want a block that detects if two different 角色s are touching.[1] The advantage of such a block is that it grants a 3rd sprite the ability to sense if another two are touching. Such a block would look similar to this:

<[sprite1 v] is touching [sprite2 v]?>//category=sensing

This can be replicated with a global 变量, with one of the touching sprites checking, and setting the value, like so:

//  In Sprite1

當收到訊息 [Check for Touching v]
如果 <碰到 [角色2 v] ?> 那麼 
  變數 [Sprite1 Touching Sprite2? v] 設為 [yes]

  變數 [Sprite1 Touching Sprite2? v] 設為 [no]

//  Anywhere you want to check for the touching
廣播訊息 [Check for Touching v]
如果 <(Sprite1 Touching Sprite2?) = [yes]> 那麼 
  . . . //  put what you want if they're touching here
  . . . //  put what you want if they aren't here


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