sprite.nextFrame()

Category:Sprites

Move to the next frame for the animation for a sprite.

When the last frame is displayed and nextFrame() is executed the first frame is disaplyed.

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 play() to restart the animation. Use pause() to stop the animation.

Examples

Die Roll

Mouse over the die to move through the animation frames.

// Mouse over the die to move through the animation frames.
var sprite = createSprite(200, 200);
sprite.setAnimation("dieRed1_1");
sprite.pause();
function draw() {
  background("white");
  drawSprites();
  if (mouseIsOver(sprite)) {
    sprite.nextFrame();
  }
}

Syntax

sprite.nextFrame()

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