Triggers a sequence of blocks to run when a specific sprite touches another specific sprite.
(Opens YouTube in new tab)
Sometimes code should only be run if an event happens. In this case, when a specific sprite touches another specific sprite, the blocks attached under the event block will begin to run sequentially. If the costume
block is used in either parameter, the event will check for touches between any sprites of the matching costume(s).
This block has a drop-down menu with “when” and “while” options. “When” a sprite touches another sprite, the code will only run once. “While” a sprite is touching another sprite, the code will run over and over again until the sprites stop touching.
Examples
Example 1
Whenever the bee touches the bear, the bear will say “Ouch!”
Example 2
While the bubble sprite is touching the soap sprite, it will grow bigger. When the bubble touches a rock sprite, it will “pop” and return to its original size. Drag the bubble to move it to the soap or rock.
Syntax
whenTouching
Parameters
Name | Type | Required? | Description |
---|---|---|---|
when/while | Determines if the code runs once when the sprite touches another sprite or continuously while the sprite is touching another sprite | ||
sprite | The sprite or sprite group of the sprites touching |
Tips
- For group events, use the
this / other sprite
block in the following actions to only affect the sprite that was touched.
Found a bug in the documentation? Let us know at support@code.org.