Creates four sprites just off each edge of the screen ("topEdge", "bottomEdge", "leftEdge", "rightEdge") and a group called "edges" containing the four sprites.
createEdgeSprites is a helper command for games where you want to prevent sprites from going off the screen.
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); }
createEdgeSprites(); var sprite = createSprite(200, 200); sprite.setVelocity(randomNumber(-5, 5), randomNumber(-5, 5)); function draw() { background("white"); drawSprites(); sprite.bounceOff(edges); }
Make the walls slowly close in using the edge sprite names topEdge, bottomEdge, leftEdge and rightEdge.
// Make the walls slowly close in using the edge sprite names topEdge, bottomEdge, leftEdge and rightEdge. createEdgeSprites(); var sprite = createSprite(200, 200); sprite.setVelocity(randomNumber(-5, 5), randomNumber(-5, 5)); function draw() { background("white"); drawSprites(); topEdge.y=topEdge.y+1; bottomEdge.y=bottomEdge.y-1; leftEdge.x=leftEdge.x+1; rightEdge.x=rightEdge.x-1; sprite.bounceOff(edges); }
createEdgeSprites()
No return value. Creates four sprites just outside the edges of the screen.
setAnimation
command. All images must be first loaded and given a label using the Animation tab above the display window in Game Lab.Found a bug in the documentation? Let us know at documentation@code.org