sprite.bounciness

Category:Sprites

The velocity lost or gained by a sprite during a collision or bounce.

For example: A value of 1 is perfectly elastic, no velocity is lost. A value of 0 is perfectly inelastic, no bouncing. A value between 0 and 1 is inelastic, this is the most common in nature. A value greater than 1 is hyper-elastic, velocity is increased like in a pinball bumper

The default bounciness is 1. All sprite properties can be both accessed and updated.

Examples

My Three Bounces

Demonstrate three different bounciness levels.

// Demonstrate three different bounciness levels.
var sprite1 = createSprite(75, 200);
var sprite2 = createSprite(200, 200);
var sprite3 = createSprite(325, 200);
var wall=createSprite(200, 400, 400, 20);
sprite1.velocityY=2;
sprite2.velocityY=2;
sprite3.velocityY=2;
sprite1.bounciness=0.5;
sprite2.bounciness=1;
sprite3.bounciness=2;
function draw() {
  background("white");
  drawSprites();
  sprite1.bounceOff(wall);
  sprite2.bounceOff(wall);
  sprite3.bounceOff(wall);
}

Syntax

sprite.bounciness

Returns

The bounciness 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