Compound

Interactornape.phys.Compound (final class)

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.

____Cmp1_____
/    /    \   \
Body1 Body2--Joint Cmp2
|     |        \  |
Shp1  Shp2        Body3
|
Shp3

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.

When you add a compound to a Space, all of it's constituents get added and furthermore, those constituents cannot be added seperately.

Instance Members

@private


nape
bodies: BodyList

List of bodies directly owned by this Compound.

This list does not include those bodies belonging to sub-compounds.

@default []


List of constraints directly owned by this Compound.

This list does not include those constraints belonging to sub-compounds.

@default []


nape
compounds: CompoundList

List of compounds directly owned by this Compound.

This list does not include those compounds belonging to sub-compounds.

@default []


nape
compound: Null<Compound>

Compound that this compound belongs to.

@default null


Space this compound belongs to.

This value is immutable when this compound belongs to another parent Compound.

@default null


nape
toString(): String

@private

Returns
String

nape
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.

____Cmp1____               [Cmp2.copy()]
/    /        \
Body1 Body2___     Cmp2        null    Cmp2'
|     |     \     /  \         \    /    \
Shp1  Shp2     Joint--Body3       Joint'--Body3'
|                   |
Shp3               Shp3'

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.

Returns
Compound

nape
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.


nape
visitBodies(lambda: Function): Void

Method to iterate over all bodies contained directly or indirectly by this Compound.

Name Type Description
lambda Function The method to apply to each Body.

nape
visitConstraints(lambda: Function): Void

Method to iterate over all constraints contained directly or indirectly by this Compound.

Name Type Description
lambda Function The method to apply to each Constraint.

nape
visitCompounds(lambda: Function): Void

Method to iterate over all compounds contained directly or indirectly by this Compound.

Name Type Description
lambda Function The method to apply to each Compound.

nape
COM(?weak: Bool = false): nape.geom.Vec2

Compute centre of mass of Compound.

Name Type Default Description
weak Bool false 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 Description
nape.geom.Vec2 The centre of mass of compound.

nape
translate(translation: nape.geom.Vec2): Compound

Translate entire compound.

This is equivalent to: compound.visitBodies(function (b) b.translate(translation))

Name Type Description
translation nape.geom.Vec2 The translation to apply to the Compound.
Returns Description
Compound A reference to this Compound.

nape
rotate(centre: nape.geom.Vec2, angle: Float): Compound

Rotate entire compound about a point.

This is equivalent to: compound.visitBodies(function (b) b.rotate(centre, angle))

Name Type Description
centre nape.geom.Vec2 The centre of rotation in world coordinates.
angle Float The clockwise angle of rotation in radians.
Returns Description
Compound A reference to this Compound.

nape
new(): Void

Construct a new Compound.

@result The constructed Compound.

Private Members

Metadata

Name Parameters
:final -