sprite.lifetime

Category:Sprites

Cycles before sprite self removal.

Usually set before the draw() cycle to initiate a countdown. sprite.lifetime is reduced by 1 in every draw() cycle. At 0 it will call a sprite.remove(). Default value is -1 which disables the lifetime for that sprite.

Examples

var sprite = createSprite(200, 200);
sprite.lifetime=50;
function draw() {
  background("white");
  drawSprites();
}

Syntax

sprite.lifetime

Returns

The lifetime of the sprite.

Tips

  • Sprites all have the same properties and you use the dot notation (combining the name of the sprite, followed by a dot, with the label of the property) to both access and update the property 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