Group

Group

new Group()

Look at the Group reference pages before reading these docs. A Group is an array of sprites with similar traits and behaviors. Group extends Array, so you can use them in for of loops. They inherit all the functions and properties of standard arrays such as `group.length` and functions like `group.includes()`. Changing a group setting changes it for all the sprites in the group, similar to class inheritance. Groups can have subgroups, creating a hierarchy of inheritance. The top level group is a q5 instance level variable named `allSprites` that contains all the sprites added to the sketch.
Source:

Extends

Classes

Group

Members

amount :Number

Depending on the value that the amount property is set to, the group will either automatically create or delete sprites.
Source:
Type:
  • Number

ani :Ani

Reference to the group's current animation.
Source:
Type:

animation :Ani

Reference to the group's current animation.
Source:
Type:

anis :Anis

The group's animations.
Source:
Type:

diameter :Number

Source:
Type:
  • Number

height :Number

Source:
Type:
  • Number

image :Image

The group's image.
Source:
Type:
  • Image

img :Image

Alias for `group.image`.
Source:
Type:
  • Image

velocity :Vector

The sprite's velocity vector {x, y}
Default Value:
  • {x: 0, y: 0}
Source:
Type:
  • Vector

width :Number

Source:
Type:
  • Number

Methods

applyForce()

Source:

applyForceScaled()

Source:

applyTorque()

Source:

attractTo()

Source:

collided(target, callbackopt) → {Boolean}

Returns true on the first frame that the group no longer overlaps with the target group.
Source:
Parameters:
Name Type Attributes Description
target Group
callback function <optional>
Returns:
Type:
Boolean

collides(target, callbackopt)

Returns true on the first frame that the group collides with the target group. Custom collision event handling can be done by using this function in an if statement or adding a callback as the second parameter.
Source:
Parameters:
Name Type Attributes Description
target Group
callback function <optional>

colliding(target, callbackopt) → {Number}

Returns the amount of frames that the group has been colliding with the target group for, which is a truthy value. Returns 0 if the group is not colliding with the target group.
Source:
Parameters:
Name Type Attributes Description
target Group
callback function <optional>
Returns:
Type:
Number
frames

cull(top, bottom, left, right, cbopt) → {Number}

Delete sprites that go outside the given culling boundary relative to the camera. Sprites with chain colliders can not be culled. Can also be used with a uniform size for all boundaries, see example.
Source:
Parameters:
Name Type Attributes Description
top Number the distance that sprites can move below the canvas before they are deleted
bottom Number the distance that sprites can move below the canvas before they are deleted
left Number the distance that sprites can move beyond the left side of the canvas before they are deleted
right Number the distance that sprites can move beyond the right side of the canvas before they are deleted
cb function <optional>
the function to be run when a sprite is culled, it's given the sprite being culled, if no callback is given then the sprite is deleted
Returns:
Type:
Number
the number of sprites culled
Example
// alternate uniform size syntax
group.cull(100, callback);

delete()

Deletes the group and all its sprites from the world and every other group they belong to. Don't attempt to use a group after deleting it.
Source:

deleteAll()

Deletes all the sprites in the group from the world and every other group they belong to. Does not delete the group itself.
Source:

draw()

Draws all the sprites in the group in ascending order by `sprite.layer`.
Source:

move()

Source:

moveAway()

Source:

moveTo()

Source:

moveTowards()

Source:

overlapped(target, callbackopt) → {Boolean}

Returns true on the first frame that the group no longer overlaps with the target group.
Source:
Parameters:
Name Type Attributes Description
target Group
callback function <optional>
Returns:
Type:
Boolean

overlapping(target, callbackopt) → {Number}

Returns the amount of frames that the group has been overlapping with the target group for, which is a truthy value. Returns 0 if the group is not overlapping with the target group.
Source:
Parameters:
Name Type Attributes Description
target Group
callback function <optional>
Returns:
Type:
Number
frames

overlaps(target, callbackopt)

Returns true on the first frame that the group overlaps with the target group. Custom overlap event handling can be done by using this function in an if statement or adding a callback as the second parameter.
Source:
Parameters:
Name Type Attributes Description
target Group
callback function <optional>

pop() → {Sprite}

Removes the last sprite in the group from the group.
Source:
Returns:
Type:
Sprite
the removed sprite or undefined if the group is empty

postDraw()

Runs every group sprite's post draw function.
Source:

push(…sprites) → {Number}

Adds a sprite or multiple sprites to the group at the end of the group list, just like the `Array.push()` method. Instead of creating a sprite and adding it to a group with this method, it's better to use the group Sprite constructor instead, `new group.Sprite()`, which both creates a group sprite using soft inheritance and adds it to the group list.
Source:
Parameters:
Name Type Attributes Description
sprites Sprite <repeatable>
The sprite or sprites to be added
Returns:
Type:
Number
the new length of the group

remove(item) → {Sprite}

Removes a sprite from this group and its sub groups (if any), but does not delete it from the world.
Source:
Parameters:
Name Type Description
item Sprite | Number the sprite to be deleted or its index
Returns:
Type:
Sprite
the deleted sprite or undefined if the specified sprite was not found

repelFrom()

Source:

shift() → {Sprite}

Removes the last sprite in the group from the group.
Source:
Returns:
Type:
Sprite
the removed sprite or undefined if the group is empty

size()

Alias for group.length
Deprecated:
  • Yes
Source:

splice(start, removalCount, …sprites) → {Array:.<Sprite:>}

If removalCount is greater than 0, that amount of sprites starting from the start index will be removed from this group and its sub groups recursively (if any), Then any provided sprites will be added at the start index to this group and at the end of each of its parent groups recursively, if not already present in parent groups.
Source:
Parameters:
Name Type Attributes Description
start Number start index
removalCount Number number of sprites to remove, starting from the start index
sprites Sprite <repeatable>
sprites to add at start index
Returns:
Type:
Array:.<Sprite:>
the removed sprites

toString() → {String}

Returns the group's unique identifier.
Source:
Returns:
Type:
String
groupID

unshift(…sprites) → {Number}

Adds one or more sprites to the beginning of the group.
Source:
Parameters:
Name Type Attributes Description
sprites Sprite <repeatable>
the sprite or sprites to be added
Returns:
Type:
Number
the new length of the group

update()

Updates all the sprites in the group.
Source: