Makes each sprite in the group bounce off the target when they touch each other. The target keeps moving as before.
Most games will involve sprites colliding with each other. There are four types of collisions available in Game Lab: bounce
, bounceOff
, collide
and displace
. These blocks will cause a certain type of interaction between each sprite and its target and must be used within the draw
function.
Keep all the bad vibes from getting you down! Use the mouse to move around your emoji and stop the mean emojis from reaching the bottom
// Stay cool! Keep all the bad vibes from getting you down. // Uses createGroup to make a bunch of bouncing baddies, // createEdgeSprites to make sure the baddies don't just fly off. var cool = createSprite(200, 325); cool.setAnimation("cool"); createEdgeSprites(); var group = createGroup(); for (var i = 0; i < 20; i++) { var sprite = createSprite(randomNumber(0, 400), randomNumber(0, 100), 10, 10); sprite.velocityY=randomNumber(5, 10); sprite.velocityX=randomNumber(-5, 5); sprite.bounciness = 1 group.add(sprite); } group.setAnimationEach("mean"); function draw() { background("white"); drawSprites(); cool.x = World.mouseX; group.bounceOff(cool); group.bounceOff(topEdge); group.bounceOff(leftEdge); group.bounceOff(rightEdge); }
group.bounceOff(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