Class: Group

Carrot.Group(game)

Carrot.Group

Constructor

new Group(game)

Groups are containers storing game objects (sprites). They are added automatically to the world container.
Parameters:
Name Type Description
game Carrot.Game The core game object.
Source:

Methods

addChild(entity)

Adds an entity to a group. The entity can be a sprite or another group.
Parameters:
Name Type Description
entity Carrot.Group | Carrot.Sprite The entity to add.
Source:

countActive() → {integer}

Counts the active sprites in the group.
Source:
Returns:
Type
integer

countInactive() → {integer}

Counts the inactive sprites in the group.
Source:
Returns:
Type
integer

create(xopt, yopt, keyopt, frameopt, activeopt) → {Carrot.Sprite}

Creates a sprite and adds it to the group.
Parameters:
Name Type Attributes Default Description
x integer <optional>
0 The x coordinate in the world of the sprite.
y integer <optional>
0 The y coordinate in the world of the sprite.
key string <optional>
null This is the image for the sprite. If left empty, the sprite will be just a green rectangle.
frame integer <optional>
0 Only for spritesheets: The starting frame of the image. If not passed, it will be 0, the first frame.
active boolean <optional>
false The default active property of the sprites.
Source:
Returns:
Type
Carrot.Sprite

createMultiple(quantityopt, xopt, yopt, keyopt, frameopt, activeopt) → {Array.<Carrot.Sprite>}

Creates multiple sprites and adds them to the group.
Parameters:
Name Type Attributes Default Description
quantity integer <optional>
0 The quantity of sprites to create.
x integer <optional>
0 The x coordinate in the world of the sprite.
y integer <optional>
0 The y coordinate in the world of the sprite.
key string <optional>
null This is the image for the sprite. If left empty, the sprite will be just a green rectangle.
frame integer <optional>
0 Only for spritesheets: The starting frame of the image. If not passed, it will be 0, the first frame.
active boolean <optional>
false The default active property of the sprites.
Source:
Returns:
Type
Array.<Carrot.Sprite>

destroy(destroyChildrenopt)

Destroys the group and removes it entirely from the game world.
Parameters:
Name Type Attributes Default Description
destroyChildren boolean <optional>
false If true, all the children of the sprite and their children are destroyed, too.
Source:

getInactive(createIfNullopt, xopt, yopt, keyopt, frameopt) → {Carrot.Sprite}

Returns an inactive sprite from the group.
Parameters:
Name Type Attributes Default Description
createIfNull boolean <optional>
false If no inactive sprite could be found, create one, add it to this group and return it.
x integer <optional>
0 The x coordinate in the world of the sprite.
y integer <optional>
0 The y coordinate in the world of the sprite.
key string <optional>
null This is the image for the sprite. If left empty, the sprite will be just a green rectangle.
frame integer <optional>
0 Only for spritesheets: The starting frame of the image. If not passed, it will be 0, the first frame.
Source:
Returns:
Type
Carrot.Sprite

removeChild(entity)

Removes the given entity from a group.
Parameters:
Name Type Description
entity Carrot.Group | Carrot.Sprite The entity to remove.
Source:

setAll(property, value, activeopt)

Iterates all children of the group and sets their `property` to the given `value`.
Parameters:
Name Type Attributes Default Description
property string The property to change.
value any The new value for the property.
active boolean <optional>
true Defines if the active or the inactive sprites shall be affected.
Source: