sprite.play()

Category:Sprites

Start the automatic frame advance for the animation for a sprite.

Use the Animation tab to load multiple images which make up the frames for a labeled animation for your sprite. By default all frames are displayed one after another in round robin fashion. The speed is set by the slider in the Animation tab. Use pause() to stop the animation.

Examples

Swat the Bee

Click on the bee to make it stop flying and fall down. Then start a new bee.

// Click on the bee to make it stop flying and fall down. Then start a new bee.
createEdgeSprites();
var sprite = createSprite(200, 200);
sprite.setAnimation("bee_1");
sprite.x = 400;
sprite.y = randomNumber(0, 400);
sprite.velocityX = randomNumber(-5, -1);
function draw() {
  background("white");
  drawSprites();
  if (mousePressedOver(sprite)) {
    sprite.pause();
    sprite.velocityX = 0;
    sprite.velocityY = 5;
  }
  if (sprite.x < 0 || sprite.y > 400) {
    sprite.play();
    sprite.x = 400;
    sprite.y = randomNumber(0, 400);
    sprite.velocityX = randomNumber(-5, -1);
    sprite.velocityY = 0;
  }
}

Syntax

sprite.play()

Returns

No return value. Changes output in the display after drawSprites() is called.

Tips

  • Sprites all have the same functions and you use the dot notation (combining the name of the sprite, followed by a dot, with the function name) to call the function for that sprite.
  • Any changes to the properties of a sprite will not be seen until after drawSprites() is called.

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