sprite.pause()
Pause 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 play()
to restart the animation.
Examples
Swat the Bee
Click on the bee to make it stop flying and fall down.
// Click on the bee to make it stop flying and fall down.
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.pause()
Returns
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 support@code.org.