group.setScaleEach()

Category:Groups

Shrink or grow all the sprites in a group keeping the height to width ratio the same.

For example, a value of 2 will be make the sprite twice as big and a value of 0.5 will make the sprite half as big. Scaling up may make images blurry. The scale should always be a positive number.

The default scale is 1.

Examples

var group = createGroup();
group.add(createSprite(100, 200));
group.add(createSprite(300, 200));
function draw() {
  background("white");
  drawSprites();
  if (keyDown("right")){
      group.setScaleEach(1.5);
  }
  if (keyDown("left")){
      group.setScaleEach(0.1);
  }
}

Syntax

group.setScaleEach(scale)

Parameters

NameTypeRequired?Description
scale Number The positive scale to apply to all the sprites in the group.

Returns

No return value. Changes output in the display after drawSprites() is called.

Tips

  • Groups of sprites all have the same functions and you use the dot notation (combining the name of the group, followed by a dot, with the function name) to call the function for that group of sprites.
  • Any changes to the properties of a sprite will not be seen until after drawSprites() is called.
  • If setColliderEach() is called for group before it is scaled, the collider is not scaled. But if a group of sprites is first scaled and then the collider set, the scale is also applied to the collider.

Found a bug in the documentation? Let us know at documentation@code.org