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.

Constructor

new()

Construct a new Compound.

@result The constructed Compound.

Variables

@:value(null)zpp_inner:ZPP_Compound = null

@private

read onlybodies:BodyList

List of bodies directly owned by this Compound.

This list does not include those bodies 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.

read onlycompounds:CompoundList

List of compounds directly owned by this Compound.

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

compound:Null<Compound>

Compound that this compound belongs to.

space:Null<Space>

Space this compound belongs to.

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

Methods

@:keeptoString():String

@private

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()]
 /    /        &#92;

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.

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.

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.

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.

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.

@:value({ weak : false })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.

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.

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.

Inherited Variables

Defined by Interactor

@:value(null)zpp_inner_i:ZPP_Interactor = null

@private

read onlyid:Int

Unique id of this Interactor.

read onlyuserData:Dynamic<Dynamic>

Dynamic object for user to store additional data.

This object cannot be set, only its dynamically created properties may be set. In AS3 the type of this property is &#42

This object will be lazily constructed so that until accessed for the first time, will be null internally.

read onlycastShape:Null<Shape>

Fast equivalent to cast(interactor, Shape)

read onlycastBody:Null<Body>

Fast equivalent to cast(interactor, Body)

read onlycastCompound:Null<Compound>

Fast equivalent to cast(interactor, Compound)

group:Null<InteractionGroup>

InteractionGroup assigned to this Interactor.

read onlycbTypes:CbTypeList

Set of CbType's assigned to this Interactor.

Inherited Methods

Defined by Interactor

inlineisShape():Bool

Fast equivalent to Std.isOfType(interactor, Shape)

Returns:

true if this Interactor is a Shape.

inlineisBody():Bool

Fast equivalent to Std.isOfType(interactor, Body)

Returns:

true if this Interactor is a Body.

inlineisCompound():Bool

Fast equivalent to Std.isOfType(interactor, Compound)

Returns:

true if this Interactor is a Compound.