Makes each sprite and the target overlap when they touch each other. Neither the sprite and the target change how they are moving.
Most games will involve sprites colliding with each other. This is the fifth, and default, type of collision available in Game Lab. The collision blocks will cause a certain type of interaction between the sprite and its target and must be used within the draw function.
group.isTouching()
is effectively the same, but is strictly a boolean check.
The up key turns on the shield and makes the dots bounce off, otherwise they overlap.
// The up key turns on the shield and makes the dots bounce off, otherwise they overlap. createEdgeSprites(); var block = createSprite(200, 200); var group = createGroup(); for (var i = 0; i < 100; i++) { var sprite = createSprite(randomNumber(0, 400), randomNumber(0, 400), 5, 5); sprite.shapeColor='red'; sprite.setVelocity(randomNumber(1, 5), randomNumber(1, 5)); group.add(sprite); } function draw() { background("white"); drawSprites(); if (keyDown("up")) { group.bounceOff(block); } else { group.overlap(block); } group.bounceOff(topEdge); group.bounceOff(bottomEdge); group.bounceOff(leftEdge); group.bounceOff(rightEdge); }
group.overlap(target)
Name | Type | Required? | Description |
---|---|---|---|
target | Sprite or Group | The name of the target sprite or target group you want to check for a collision. |
Boolean true or false. Changes output in the display after the sprites touch and drawSprites() is called.
draw
function, and then depending on the collision type, updating the sprite and target velocityX
and velocityY
properties.setCollider
to change the shape and size of the collider area and set debug
to true for the sprites.Found a bug in the documentation? Let us know at documentation@code.org