Makes the 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.
isTouching()
is effectively the same, but is strictly a boolean check.
var sprite1 = createSprite(75, 250, 50, 50); sprite1.velocityX=2; sprite1.velocityY=-1; var sprite2 = createSprite(250, 250, 50, 50); sprite2.velocityX=-1; sprite2.velocityY=-0.5; // since sprite2 was creasted second it has a higher depth number and will overlap sprite1. function draw() { background("white"); sprite1.overlap(sprite2); // Since overlap is the default collision this code would work the same without this statement. drawSprites(); }
sprite.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.
sprite.depth
property.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