group.setWidthEach()
Category:Groups
Sets the width of the sprite placeholder rectangle for every sprite in the group.
The default width is 100.
Examples
var group = createGroup();
group.add(createSprite(100, 200));
group.add(createSprite(300, 200));
function draw() {
background("white");
drawSprites();
if (mouseDown("leftButton")){
group.setWidthEach(20);
}
if (mouseDown("rightButton")){
group.setWidthEach(100);
}
}
Syntax
group.setWidthEach(width)
Parameters
Name | Type | Required? | Description |
---|---|---|---|
width | Number | The width of the sprites in pixels. |
Returns
No return value. Changes output in the display after drawSprites() is called.
Tips
- use
group.setScaleEach
to resize a sprite and keep the height to width ratio constant. - 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 support@code.org.