Use the frame number to set the frame 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 play()
to restart the animation. Use pause()
to stop the animation.
Use the mouse to move the smiley face. High in the display for happy, middle of the display for surprised, low in the display for sad.
// Use the mouse to move the smiley face. // High in the display for happy, middle of the display for surprised, low in the display for sad. var sprite = createSprite(200, 200); sprite.setAnimation("smiley"); sprite.pause(); function draw() { background("white"); drawSprites(); sprite.x = World.mouseX; sprite.y = World.mouseY; if (sprite.y < 100) { sprite.setFrame(0); } else if (sprite.y > 300) { sprite.setFrame(1); } else { sprite.setFrame(2); } }
sprite.setFrame(frame)
Name | Type | Required? | Description |
---|---|---|---|
frame | Number | The frame number of the animation you want the sprite to use. The first frame is frame 0. |
No return value. Changes output in the display after drawSprites() is called.
drawSprites()
is called.Found a bug in the documentation? Let us know at documentation@code.org