Compound represents a grouping of physics objects into a single object.
This compound owns its constituents and works in the callback system and with
respect to adding/removing from a Space as a single object.
For example if you have a complex car built with several bodies and constraints you might store this in a Compound providing an easy way of removing/adding/copying the Car as well as being able to get a single callback for when the car collides with something.____Cmp1_____ / / \ \
Body1 Body2--Joint Cmp2 | | \ | Shp1 Shp2 Body3
| Shp3
When you add a compound to a Space, all of it's constituents get added and furthermore, those constituents cannot be added seperately.
Constructor
Variables
read onlybodies:BodyList
List of bodies directly owned by this Compound.
This list does not include those bodies belonging to sub-compounds.
read onlycompounds:CompoundList
List of compounds directly owned by this Compound.
This list does not include those compounds belonging to sub-compounds.
read onlyconstraints:ConstraintList
List of constraints directly owned by this Compound.
This list does not include those constraints belonging to sub-compounds.
Methods
COM(weak:Bool = false):Vec2
Compute centre of mass of Compound.
Parameters:
weak | If true, the returned Vec2 will be automatically released to the object pool when passed as an argument to a Nape function. (default false) |
---|
Returns:
The centre of mass of compound.
Throws:
# | If Compound has no Bodies contained directly or indirectly that contain at least one Shape. |
---|
breakApart():Void
Breaking compound apart in-place.
This method will destroy the compound, moving all of it's components
to the assigned Space if this is the root compound, otherwise to the
parent compound.
Apart from being easier than doing this manually it also means that we
do not have to temporarigly remove objects from the space meaning that
things like PreListener ignored interactions will be unaffected.
copy():Compound
Produce an exact copy of this Compound.
This copy will remap owned constraints so that their body properties
refer to the newly copied bodies also owned by this compound.
If this compound tree contains any constraints that make references
to outside of this compound; then these properties will be made null.
For instance if copying Cmp1 then all is well, but if we copy Cmp2 the copied Joint will have one of it's body references null as that body is not owned directly, or indirectly by the compound.____Cmp1____ [Cmp2.copy()] / / \
Body1 Body2___ Cmp2 null Cmp2' | | \ / \ \ / \ Shp1 Shp2 Joint--Body3 Joint'--Body3'
| | Shp3 Shp3'
rotate(centre:Vec2, angle:Float):Compound
Rotate entire compound about a point.
This is equivalent to: compound.visitBodies(function (b) b.rotate(centre, angle))
Parameters:
centre | The centre of rotation in world coordinates. |
---|---|
angle | The clockwise angle of rotation in radians. |
Returns:
A reference to this Compound.
Throws:
# | If centre is null or disposed of. |
---|---|
# | If any Body in the compound is static, and this compound is in a Space. |
translate(translation:Vec2):Compound
Translate entire compound.
This is equivalent to: compound.visitBodies(function (b) b.translate(translation))
Parameters:
translation | The translation to apply to the Compound. |
---|
Returns:
A reference to this Compound.
Throws:
# | If translation is null or disposed of. |
---|---|
# | If any Body in the compound is static, and this compound is in a Space. |
visitBodies(lambda:Body ‑> Void):Void
Method to iterate over all bodies contained directly or indirectly by this Compound.
Parameters:
lambda | The method to apply to each Body. |
---|
Throws:
# | If lambda is null. |
---|
visitCompounds(lambda:Compound ‑> Void):Void
Method to iterate over all compounds contained directly or indirectly by this Compound.
Parameters:
lambda | The method to apply to each Compound. |
---|
Throws:
# | If lambda is null. |
---|
visitConstraints(lambda:Constraint ‑> Void):Void
Method to iterate over all constraints contained directly or indirectly by this Compound.
Parameters:
lambda | The method to apply to each Constraint. |
---|
Throws:
# | If lambda is null. |
---|