# Two.Group
Extends: Two.Shape
This is the primary class for grouping objects that are then drawn in Two.js. In Illustrator this is a group, in After Effects it would be a Null Object. Whichever the case, the Two.Group contains a transformation matrix and commands to style its children, but it by itself doesn't render to the screen.
# Constructor
| Argument | Description |
|---|---|
| children | A list of objects that inherit Two.Shape. For instance, the array could be a Two.Path, Two.Text, and Two.RoundedRectangle. |
# InsertChildren
Two.Group.InsertChildren
| Argument | Description |
|---|---|
| children | The objects to be inserted. |
Cached method to let renderers know children have been added to a Two.Group.
# RemoveChildren
Two.Group.RemoveChildren
| Argument | Description |
|---|---|
| children | The objects to be removed. |
Cached method to let renderers know children have been removed from a Two.Group.
# OrderChildren
Two.Group.OrderChildren
Cached method to let renderers know order has been updated on a Two.Group.
# fill
Two.Group.fill
The value of what all child shapes should be filled in with.
See: https://developer.mozilla.org/en-US/docs/Web/CSS/color_value (opens new window) for more information on CSS's colors as String.
# stroke
Two.Group.stroke
The value of what all child shapes should be outlined in with.
See: https://developer.mozilla.org/en-US/docs/Web/CSS/color_value (opens new window) for more information on CSS's colors as String.
# cap
Two.Group.cap
# join
Two.Group.join
# miter
Two.Group.miter
# closed
Two.Group.closed
Determines whether a final line is drawn between the final point in the vertices array and the first point of all child shapes.
# curved
Two.Group.curved
When the child's path is automatic = true this boolean determines whether the lines between the points are curved or not.
# automatic
Two.Group.automatic
Determines whether or not Two.js should calculate curves, lines, and commands automatically for you or to let the developer manipulate them for themselves.
# beginning
Two.Group.beginning
Number between zero and one to state the beginning of where the path is rendered.
Two.Group.beginning is a percentage value that represents at what percentage into all child shapes should the renderer start drawing.
# ending
Two.Group.ending
Number between zero and one to state the ending of where the path is rendered.
Two.Group.ending is a percentage value that represents at what percentage into all child shapes the renderer should stop drawing.
# additions
Two.Group.additions
An automatically updated list of children that need to be appended to the renderer's scenegraph.
# subtractions
Two.Group.subtractions
An automatically updated list of children that need to be removed from the renderer's scenegraph.
# copy
Two.Group.copy
Returns: Two.Group
| Argument | Description |
|---|---|
| group | The reference Two.Group |
Copy the properties of one Two.Group onto another.
# clone
Two.Group.clone
Returns: Two.Group
| Argument | Description |
|---|---|
| parent | The parent group or scene to add the clone to. |
Create a new instance of Two.Group with the same properties of the current group.
# toObject
Two.Group.toObject
Returns: Object
Return a JSON compatible plain object that represents the group.
# dispose
Two.Group.dispose
Returns: Two.Group
Release the group's renderer resources and detach all events. This method recursively disposes all child objects, unbinds the children collection events, and preserves the renderer type for potential re-attachment to a new renderer.
# getShapesAtPoint
Two.Group.getShapesAtPoint
Returns: Array.<Shape>
Ordered list of intersecting shapes, front to back.
| Argument | Description |
|---|---|
| x | X coordinate in world space. |
| y | Y coordinate in world space. |
| options | Hit test configuration. |
| options.visibleOnly | Limit results to visible shapes. |
| options.includeGroups | Include groups in the hit results. |
| options.mode | Whether to return all intersecting shapes or only the top-most. |
| options.deepest | Alias for mode: 'deepest'. |
| options.precision | Segmentation precision for curved geometry. |
| options.tolerance | Pixel tolerance applied to hit testing. |
| options.fill | Override fill testing behaviour. |
| options.stroke | Override stroke testing behaviour. |
| options.filter | Predicate to filter shapes from the result set. |
Traverse the group hierarchy and return shapes that contain the specified point.
# corner
Two.Group.corner
Orient the children of the group to the upper left-hand corner of that group.
# getById
Two.Group.getById
Returns: Two.Shape
- Or
nullif nothing is found.
Recursively search for id. Returns the first element found.
# getByClassName
Two.Group.getByClassName
Returns: Array.<Two.Shape>
- Or empty array if nothing is found.
Recursively search for classes. Returns an array of matching elements.
# getByType
Two.Group.getByType
Returns: Array.<Two.Shape>
- Empty array if nothing is found.
Recursively search for children of a specific type, e.g. Two.Path. Pass a reference to this type as the param. Returns an array of matching elements.
# add
Two.Group.add
| Argument | Description |
|---|---|
| objects | An array of objects to be added. Can also be supplied as individual arguments. |
Add objects to the group.
# remove
Two.Group.remove
| Argument | Description |
|---|---|
| objects | An array of objects to be removed. Can be also removed as individual arguments. If no arguments are passed, then it removes itself from its parent. |
Remove objects from the group.
# getBoundingClientRect
Two.Group.getBoundingClientRect
Returns: Object
- Returns object with top, left, right, bottom, width, height attributes.
| Argument | Description |
|---|---|
| shallow | Describes whether to calculate off local matrix or world matrix. |
Return an object with top, left, right, bottom, width, and height parameters of the group.
# strokeAttenuation
Two.Group.strokeAttenuation
When set to true, stroke width scales with transformations (default behavior). When false, stroke width remains constant in screen space for all child shapes.
When strokeAttenuation is false, this property is applied to all child shapes, making their stroke widths automatically adjust to compensate for the group's world transform scale, maintaining constant visual thickness regardless of zoom level. When true (default), stroke widths scale normally with transformations.