group.setColorEach()

Category:Groups

Sets the color of the sprite placeholder rectangle for every sprite in the group.

The default color is gray. You can assign the color in one of two ways. It can be:

  • The lowercase name of a color inside " ". A full list of color names can be found at W3 Schools - Colors
  • A call to the rgb() command.

Examples

var group = createGroup();
group.add(createSprite(100, 200));
group.add(createSprite(300, 200));
function draw() {
  background("white");
  drawSprites();
  if (mouseDown("leftButton")){
    group.setColorEach("yellow");
  }
  else {
        group.setColorEach("green");
  }
}

Syntax

group.setColorEach(color)

Parameters

NameTypeRequired?Description
color Color The lowercase name of a color inside " " or a call to the rgb() command.

Returns

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

Tips

  • A full list of color names can be found at W3 Schools - Colors.
  • For more specific color selection, or to randomize color selection, use rgb() as a parameter to fill instead of a color name.
  • 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.

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