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

Emoji Eyes

Mouse over the emoji to move through the animation frames and make it's eyes move!

                            //Mouse over emoji!
var sprite = createSprite(200, 200);
sprite.setAnimation("emoji");
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