Document.png Please expand this article or section. You can help by adding more information if you are an editor. More information might be found in a section of the talk page. (April 2020)

Click sensing is the detection of mouse clicks on a sprite or the stage. It is commonly used in many Scratch projects. To sense when a sprite, backdrop, or area is clicked, there are multiple scripts and hat blocks.

Hat Blocks

The two hat blocks to sense when a sprite/stage is clicked are the When This Sprite Clicked block and the When Stage Clicked block. When the sprite/stage is clicked, the script underneath these hat blocks will run.

when stage clicked :: hat events
when this sprite clicked :: hat events
The two hat blocks.

When This Sprite Clicked

Main article: When This Sprite Clicked (block)

A hat block that senses clicks is the When This Sprite Clicked block. When the sprite in question is clicked, the script underneath this block will run. If the sprite is hidden (when the Hide block is in use), the code will not run. The code will also not run when transparent areas of the sprite is clicked.

when this sprite clicked :: hat events

When Stage Clicked

Main article: When Stage Clicked (block)

Another hat block that senses clicks is the When Stage Clicked block. Like the When This Sprite Clicked block, any code under this block will run when the stage (or backdrop, in other words) will be clicked.

when stage clicked :: hat events

Other Scripts

There are a few other scripts to sense clicking including:

when gf clicked 
forever //Another way to sense if a sprite is being clicked.
if <<mouse down?> and <touching [mouse-pointer v]>> then
...

Or

when gf clicked // Sensing if the sprite is being clicked
forever
wait until <not <mouse down?>>
wait until <mouse down?>
if <touching [mouse-pointer v]> then
...

Or

when gf clicked
forever // Sensing if the sprite is being clicked.
if <mouse down?> then
if <touching [mouse-pointer v]> then
...
Cookies help us deliver our services. By using our services, you agree to our use of cookies.