From Test-Scratch-Wiki

当角色被点击
2.0 When This Sprite Clicked.png
Category 控制类积木/事件类积木
Type 半圆形积木
Introduced in 1.0

The When This Sprite Clicked 积木 is an 事件类积木 and a 半圆形积木. 程式 that wear the block will activate once its sprite or clone of the sprite is clicked. Contrary to its definite name, the block will also execute the clone's script when the clone is clicked on.

Clicking on transparent areas of the sprite does not trigger this event, except for transparent areas surrounded by using the hollow rectangle and oval tools in the bitmap editor.

If a sprite is has been hidden by the hide block, when its location is clicked on, the script under the When This Sprite Clicked block will not activate.[1]

In the 舞台, this block is called When Stage Clicked.

历史

In Scratch 1.4, this block was called When () Clicked. It was automatically filled in with the name of the sprite it was placed on.

In Scratch 2.0, its name was changed to When This Sprite Clicked, likely to make the block name consistent for all sprites. In early versions, it was called When I Am Clicked, but this was changed for unknown reasons.

用法示例

  • Making buttons
當角色被點擊
廣播訊息 [open menu v] // an example button that opens a menu
當角色被點擊
背景換成 [meadow v] // changing backdrops
  • Interacting with objects
當角色被點擊
重複 (20) 次 
  效果 [漩渦 v] 改變 (5)
end
重複 (10) 次 
  尺寸改變 (-10)
end
  • Input controls
當角色被點擊
說出 [Hello!] (2) 秒
詢問 [How are you feeling today?] 並等待
如果 <(詢問的答案) = [Happy]> 那麼 
  說出 [That's good!] (2) 秒
end
  • Menus
當角色被點擊
尺寸設為 (90) %
等待 (0.5) 秒
尺寸設為 (100) %
廣播訊息 [Menu v]

应用

Main article: List of Block Workarounds

This block can be replicated with the following code:

當 @greenflag 被點擊
重複無限次 
  等待直到 <<滑鼠鍵被按下?> 不成立>
  等待直到 <滑鼠鍵被按下?>
  如果 <碰到 [滑鼠游標 v] ?> 那麼 
    . . .
  end
end

or

當 @greenflag 被點擊
重複無限次 
  如果 <滑鼠鍵被按下?> 那麼 
    如果 <碰到 [滑鼠游標 v] ?> 那麼 
      . . .
    end
    等待直到 <<滑鼠鍵被按下?> 不成立>
  end
end

参考

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