group.isTouching()

Category:Groups

Checks if any sprite in the group is touching the target sprite or any sprite in the target group.

All sprites have a collider area that defines the active area to detect collisions with other sprites and mouse interactions. Use setColliderEach() to change the default collider area, a rectangle, for a group of sprites.

Examples

var target = createSprite(200, 200);
target.shapeColor="green";
var group = createGroup();
for (var i = 0; i < 5; i++) {
  group.add(createSprite(randomNumber(0, 400), randomNumber(0, 400), 20, 20));
}
function draw() {
  background("white");
  drawSprites();
  if (group.isTouching(target)) {
    target.shapeColor="red";
  }
}

Syntax

group.isTouching(target)

Parameters

NameTypeRequired?Description
target Sprite or Group The name of the target sprite or target group you want to check for touching.

Returns

Boolean true or false.

Tips

  • To fine tune your collision detection use setColliderEach() to change the shape and size of the collider area and set debug to true for each sprites.
  • Groups of sprites all have the same functions and you use the dot notation (combining the name of the group, followed by a dot, with the function name) to call the function for that group of sprites.

Found a bug in the documentation? Let us know at documentation@code.org