pxt-calliope/docs/reference/game/is-touching.md

40 lines
865 B
Markdown
Raw Permalink Normal View History

2016-03-26 00:47:20 +01:00
# Touching
2016-07-13 22:10:06 +02:00
Find whether the sprite is touching another sprite you say.
Sprites are touching if they share the same LED.
```sig
game.createSprite(0, 2).isTouching(null);
2016-07-13 22:10:06 +02:00
```
## Parameters
2016-07-13 22:10:06 +02:00
* another **sprite** that might be touching the one you are checking.
2016-07-13 22:10:06 +02:00
## Returns
2016-07-13 22:10:06 +02:00
* `true` if the two sprites are touching.
2016-07-13 22:10:06 +02:00
## Example
2016-07-13 22:10:06 +02:00
This program creates two sprites called ``matter`` and ``antimatter``,
and then checks whether they are touching. If they are, there is an
explosion.
2016-03-26 00:47:20 +01:00
```blocks
let matter = game.createSprite(2, 2);
let antimatter = game.createSprite(2, 2);
if (matter.isTouching(antimatter)) {
basic.pause(500);
basic.clearScreen();
basic.showString("BOOM!");
}
2016-03-26 00:47:20 +01:00
```
2016-07-13 22:10:06 +02:00
## See also
2016-07-13 22:10:06 +02:00
2016-07-14 00:04:10 +02:00
[create sprite](/reference/game/create-sprite),
[is touching edge](/reference/game/is-touching-edge),
2016-07-13 22:10:06 +02:00
[if on edge, bounce](/reference/game/if-on-edge-bounce)