Space

nape.space.Space (final class)

The heart of all Nape simulations.

Instance Members

@private


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

@default {}


nape
gravity: nape.geom.Vec2

Space gravity.

Units are of pixels/second/second @default (0,0)


nape
broadphase: Broadphase

Broadphase type in use.


nape
sortContacts: Bool

Flag controlling sorting of contact points.

If true, then collisions will be resolved in an order defined by their penetration depths. This can be shown to improve stability of the physics as well as making simulations more consistent regardless of which broadphase is used.

Having sorting enabled obviously incurs a cost, and you may consider disabling it if you are having issues with performance (Though things such as number of physics iterations will have much greater bearing on performance than this, especcialy since enabling this may permit you to use less iterations).

@default true


nape
worldAngularDrag: Float

Angular drag applied to all bodies in Space.

This represents the fraction of a body's angular velocity which will be removed per second. This value has no unit attached.

@default 0.015


nape
worldLinearDrag: Float

Linear drag applied to all bodies in Space.

This represents the fraction of a body's linear velocity which will be removed per second. This value has no unit attached.

@default 0.015


List of all Compounds directly placed in space.

This list is mutable, and adding an element to this list is one way of adding a Compound to this Space equivalent to: compound.space = space

This list is only those compounds directly placed in the space, any compound that is a child of another compound will not be in this list.


List of all Bodys directly placed in space.

This list is mutable, and adding an element to this list is one way of adding a Body to this Space equivalent to: body.space = space

This list is only those bodies directly placed in the space, any body that is a child of a Compound will not be in this list.


nape
liveBodies: nape.phys.BodyList

List of all active dynamic Bodies in space.

This list contains all dynamic bodies that are awake regardless of their containment in a Compound.

This list is immutable.


List of all Constraints directly placed in space.

This list is mutable, and adding an element to this list is one way of adding a Constraint to this Space equivalent to: constraint.space = space

This list is only those bodies directly placed in the space, any constraint that is a child of a Compound will not be in this list.


nape
liveConstraints: nape.constraint.ConstraintList

List of all active Constraints in space.

This list contains all constraints regardless of their containment in a Compound.

This list is immutable.


nape
world: nape.phys.Body

Static, immutable Body for constraint purposes.

This is a completely static, uncollidable, uninteractable Body with no Shapes, that cannot be modified in any way.

Its purpose is to provide a means for attaching Constraints from one Body to the Space itself, for instance pinning a body against a static point in space.


List of all active arbiters in Space.

This list is immutable.


List of all Listeners in space.

This list is mutable, and adding an element to this list is one way of adding a Listener to this Space equivalent to: listener.space = space


nape
timeStamp: Int

The time stamp of this Space object.

This is equal to the number of times that space.step(..) has been invoked.


nape
elapsedTime: Float

The elapsed simulation time.

This is the total amount of 'time' that has elapsed in the Space simulation.


nape
visitBodies(lambda: Function): Void

Apply given function to all bodies in space.

This method is a way to iterate over 'every' Body in the Space regardless of containment in a Compound.

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

nape
visitConstraints(lambda: Function): Void

Apply given function to all constraints in space.

This method is a way to iterate over 'every' Constraint in the Space regardless of containment in a Compound.

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

nape
visitCompounds(lambda: Function): Void

Apply given function to all compounds in space.

This method is a way to iterate over 'every' Compound in the Space regardless of containment in another Compound.

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

nape
clear(): Void

Clear the Space of all objects.

Things such as the elapsed simulation time, and time step will too be reset to 0.

Parameters such as gravity, and worldLinearDrag will be untouched by this operation.


nape
step(deltaTime: Float, ?velocityIterations: Int = 10, ?positionIterations: Int = 10): Void

Step simulation forward in time.

Name Type Default Description
deltaTime Float The number of seconds to simulate. For 60fps physics you would use a value of 1/60.
velocityIterations Int 10 The number of iterations to use in resolving errors in the velocities of objects. This is together with collision detection the most expensive phase of a simulation update, as well as the most important for stable results. (default 10)
positionIterations Int 10 The number of iterations to use in resolving errors in the positions of objects. This is far more lightweight than velocity iterations, as well as being less important for the stability of results. (default 10)

Determine the interaction type that would occur between a pair of Shapes.

This function takes into account everything possible, and ignoring the callback system will tell you precisely the type of interaction (if any at all) which will occur between these Shapes.

This function can only work if the Shapes belong to a Body.

This function can only make use of any constraints 'ignore' property to determine if 'null' should be returned if the constraints being used are inside of a Space.

Name Type Description
shape1 nape.shape.Shape The first Shape to test.
shape2 nape.shape.Shape The second Shape to test.
Returns Description
Null<nape.callbacks.InteractionType> The interaction type that will occur between these shapes, or null if no interaction will occur.

nape
shapesUnderPoint(point: nape.geom.Vec2, ?filter: nape.dynamics.InteractionFilter = null, ?output: nape.shape.ShapeList = null): nape.shape.ShapeList

Evaluate all Shapes under a given Point.

If the filter argument is non-null, then only shapes who's filter agrees to 'collide' will be considered.

Name Type Default Description
point nape.geom.Vec2 The point to evaluate shapes.
filter nape.dynamics.InteractionFilter null Optional filter to pick and choose shapes, based on whether the filters agree to collide. (default null)
output nape.shape.ShapeList null Optional list to append results to instead of creating a new list (default null).
Returns Description
nape.shape.ShapeList A list of all the Shapes containing the given point.

nape
bodiesUnderPoint(point: nape.geom.Vec2, ?filter: nape.dynamics.InteractionFilter = null, ?output: nape.phys.BodyList = null): nape.phys.BodyList

Evaluate all Bodies under a given Point.

If the filter argument is non-null, then only bodies with a shape containing the given point whose filter agrees to 'collide' will be considered.

Name Type Default Description
point nape.geom.Vec2 The point to evaluate bodies.
filter nape.dynamics.InteractionFilter null Optional filter to pick and choose shapes, based on whether the filters agree to collide. (default null)
output nape.phys.BodyList null Optional list to append results to instead of creating a new list (default null).
Returns Description
nape.phys.BodyList A list of all the Bodies containing the given point.

nape
shapesInAABB(aabb: nape.geom.AABB, ?containment: Bool = false, ?strict: Bool = true, ?filter: nape.dynamics.InteractionFilter = null, ?output: nape.shape.ShapeList = null): nape.shape.ShapeList

Evaluate all Shapes given an AABB.

If the filter argument is non-null, then only shapes who's filter agrees to 'collide' will be considered.

Name Type Default Description
aabb nape.geom.AABB The bounding box to query shapes by,
containment Bool false If true, then only Shapes entirely contained (Rather than simply intersected) will be considered. (default false)
strict Bool true If false, then the Shape's bounding box will be used to classify the Shape, instead of the Shape itself. (default true)
filter nape.dynamics.InteractionFilter null Optional filter to pick and choose shapes, based on whether the filters agree to collide. (default null)
output nape.shape.ShapeList null Optional list to append results to instead of creating a new list (default null).
Returns Description
nape.shape.ShapeList A list of all the shapes for given AABB.

nape
bodiesInAABB(aabb: nape.geom.AABB, ?containment: Bool = false, ?strict: Bool = true, ?filter: nape.dynamics.InteractionFilter = null, ?output: nape.phys.BodyList = null): nape.phys.BodyList

Evaluate all Bodies given an AABB.

If the filter argument is non-null, then only bodies with a shape classified as being part of the AABB, whose filter agrees to collide will be considered.

Name Type Default Description
aabb nape.geom.AABB The bounding box to query bodies by,
containment Bool false If true, then only Bodies entirely contained (Rather than simply intersecting) will be considered. (default false)
strict Bool true If false, then the body's shape's bounding box will be used to classify the shapes of the body, instead of the Shape itself. (default true)
filter nape.dynamics.InteractionFilter null Optional filter to pick and choose shapes, based on whether the filters agree to collide. (default null)
output nape.phys.BodyList null Optional list to append results to instead of creating a new list (default null).
Returns Description
nape.phys.BodyList A list of all the shapes for given AABB.

nape
shapesInCircle(position: nape.geom.Vec2, radius: Float, ?containment: Bool = false, ?filter: nape.dynamics.InteractionFilter = null, ?output: nape.shape.ShapeList = null): nape.shape.ShapeList

Evaluate all Shapes given a circle.

If the filter argument is non-null, then only shapes who's filter agrees to 'collide' will be considered.

Name Type Default Description
position nape.geom.Vec2 The position of the centre of the circle.
radius Float The radius of the circle.
containment Bool false If true, then only Shapes entirely contained (Rather than simply intersected) will be considered. (default false)
filter nape.dynamics.InteractionFilter null Optional filter to pick and choose shapes, based on whether the filters agree to collide. (default null)
output nape.shape.ShapeList null Optional list to append results to instead of creating a new list (default null).
Returns Description
nape.shape.ShapeList A list of all the shapes for given circle.

nape
bodiesInCircle(position: nape.geom.Vec2, radius: Float, ?containment: Bool = false, ?filter: nape.dynamics.InteractionFilter = null, ?output: nape.phys.BodyList = null): nape.phys.BodyList

Evaluate all Bodies given a circle.

If the filter argument is non-null, then only bodies with a shape classified as being part of the circle, whose filter agrees to collide will be considered.

Name Type Default Description
position nape.geom.Vec2 The position of the centre of the circle.
radius Float The radius of the circle.
containment Bool false If true, then only Bodies entirely contained (Rather than simply intersecting) will be considered. If a filter is supplied, only shapes that agree to collide will be used in this containment check. (default false)
filter nape.dynamics.InteractionFilter null Optional filter to pick and choose shapes, based on whether the filters agree to collide. (default null)
output nape.phys.BodyList null Optional list to append results to instead of creating a new list (default null).
Returns Description
nape.phys.BodyList A list of all the shapes for given circle.

nape
shapesInShape(shape: nape.shape.Shape, ?containment: Bool = false, ?filter: nape.dynamics.InteractionFilter = null, ?output: nape.shape.ShapeList = null): nape.shape.ShapeList

Evaluate all Shapes given another shape.

If the filter argument is non-null, then only shapes who's filter agrees to 'collide' will be considered. The input shape's own filter is never used in this method. The input shape is considered a purely geometric object.

The input shape must be part of a Body so as to be well defined.

Name Type Default Description
shape nape.shape.Shape The shape to use in classifying other shapes.
containment Bool false If true, then only Shapes entirely contained (Rather than simply intersected) will be considered. (default false)
filter nape.dynamics.InteractionFilter null Optional filter to pick and choose shapes, based on whether the filters agree to collide. (default null)
output nape.shape.ShapeList null Optional list to append results to instead of creating a new list (default null).
Returns Description
nape.shape.ShapeList A list of all the shapes for given shape.

nape
bodiesInShape(shape: nape.shape.Shape, ?containment: Bool = false, ?filter: nape.dynamics.InteractionFilter = null, ?output: nape.phys.BodyList = null): nape.phys.BodyList

Evaluate all Bodies given a shape.

If the filter argument is non-null, then only bodies with a shape classified as being part of the input shape, whose filter agrees to collide will be considered. The input shape is considered a purely geometric

The input shape must be part of a Body so as to be well defined.

Name Type Default Description
shape nape.shape.Shape The shape to use in classifying other shapes.
containment Bool false If true, then only Bodies entirely contained (Rather than simply intersecting) will be considered. (default false)
filter nape.dynamics.InteractionFilter null Optional filter to pick and choose shapes, based on whether the filters agree to collide. (default null)
output nape.phys.BodyList null Optional list to append results to instead of creating a new list (default null).
Returns Description
nape.phys.BodyList A list of all the bodies for given shape.

nape
shapesInBody(body: nape.phys.Body, ?filter: nape.dynamics.InteractionFilter = null, ?output: nape.shape.ShapeList = null): Null<nape.shape.ShapeList>

Evaluate all Shapes given a Body.

If the filter argument is non-null, then only shapes who's filter agrees to 'collide' will be considered. The input body's shape's own filters are never used in this method. The input body is considered a purely geometric object.

Name Type Default Description
body nape.phys.Body The body to use in classifying other shapes.
filter nape.dynamics.InteractionFilter null Optional filter to pick and choose shapes, based on whether the filters agree to collide. (default null)
output nape.shape.ShapeList null Optional list to append results to instead of creating a new list (default null).
Returns Description
Null<nape.shape.ShapeList> A list of all the shapes for given body.

nape
bodiesInBody(body: nape.phys.Body, ?filter: nape.dynamics.InteractionFilter = null, ?output: nape.phys.BodyList = null): Null<nape.phys.BodyList>

Evaluate all Bodies given a Body.

If the filter argument is non-null, then only bodies with a shape classified as being part of the input body, whose filter agrees to collide will be considered. The input body is considered a purely geometric

Name Type Default Description
body nape.phys.Body The body to use in classifying other bodies.
filter nape.dynamics.InteractionFilter null Optional filter to pick and choose shapes, based on whether the filters agree to collide. (default null)
output nape.phys.BodyList null Optional list to append results to instead of creating a new list (default null).
Returns Description
Null<nape.phys.BodyList> A list of all the bodies for given body.

nape
convexCast(shape: nape.shape.Shape, deltaTime: Float, ?liveSweep: Bool = false, ?filter: nape.dynamics.InteractionFilter = null): Null<nape.geom.ConvexResult>

Perform a convex cast for soonest collision.

This method will return only the soonest collision result (if any), to find more than this, use the convexMultiCast method. The shape will not be swept further than the time delta provided. Shapes already intersecting the sweep shape at t = 0 are ignored.

If the filter argument is null, then all shapes will be collidable otherwise only those for whose filter agrees to 'collide'.

Name Type Default Description
shape nape.shape.Shape The Shape to be cast through space. This shape must belong to a body whose velocity is used to define the sweep.
deltaTime Float The amount of time to sweep the shape forward.
liveSweep Bool false If true, then moving objects in the space will have their motion considered during the sweep. Otherwise; like with normal rayCast, objects in the space are considered un-moving for the cast. (default false)
filter nape.dynamics.InteractionFilter null Optional filter to pick and choose shapes, based on whether the filters agree to collide. (default null)
Returns Description
Null<nape.geom.ConvexResult> The soonest result (if any) of convex intersection.

nape
convexMultiCast(shape: nape.shape.Shape, deltaTime: Float, ?liveSweep: Bool = false, ?filter: nape.dynamics.InteractionFilter = null, output: nape.geom.ConvexResultList): nape.geom.ConvexResultList

Perform a convex cast for all collisions in time order.

This method will return all collisions, or an empty list if there are none. The shape will not be swept further than the time delta provided. Shapes already intersecting the sweep shape at t = 0 are ignored.

If the filter argument is null, then all shapes will be collidable otherwise only those for whose filter agrees to 'collide'.

Name Type Default Description
shape nape.shape.Shape The Shape to be cast through space. This shape must belong to a body whose velocity is used to define the sweep.
deltaTime Float The amount of time to sweep the shape forward.
liveSweep Bool false If true, then moving objects in the space will have their motion considered during the sweep. Otherwise; like with normal rayCast, objects in the space are considered un-moving for the cast. (default false)
filter nape.dynamics.InteractionFilter null Optional filter to pick and choose shapes, based on whether the filters agree to collide. (default null)
output nape.geom.ConvexResultList A list to append results to instead of allocating a new one (default null)
Returns Description
nape.geom.ConvexResultList The collision results in time order.

nape
rayCast(ray: nape.geom.Ray, ?inner: Bool = false, ?filter: nape.dynamics.InteractionFilter = null): Null<nape.geom.RayResult>

Perform a ray cast for closest result.

This method will return only the closest result (if any), to find more the first result, use the rayMultiCast method. The ray will not be cast beyond its maxDistance.

If the filter argument is null, then all shapes will be intersectable otherwise only those for whose filter agrees to 'collide'.

Name Type Default Description
ray nape.geom.Ray The ray to cast through space.
inner Bool false If true then inner surfaces of shapes will also be intersected. otherwise only the outer surfaces. (default false)
filter nape.dynamics.InteractionFilter null Optional filter to pick and choose shapes, based on whether the filters agree to collide. (default null)
Returns Description
Null<nape.geom.RayResult> The closest result (if any) of ray intersection.

nape
rayMultiCast(ray: nape.geom.Ray, ?inner: Bool = false, ?filter: nape.dynamics.InteractionFilter = null, ?output: nape.geom.RayResultList = null): nape.geom.RayResultList

Perform a ray cast for all valid results.

This method will return all intersections (in distance order) of ray with shapes in the space up to the ray's maxDistance.

If the filter argument is null, then all shapes will be intersectable otherwise only those for whose filter agrees to 'collide'.

Name Type Default Description
ray nape.geom.Ray The ray to cast through space.
inner Bool false If true then inner surfaces of shapes will also be intersected. otherwise only the outer surfaces. (default false)
filter nape.dynamics.InteractionFilter null Optional filter to pick and choose shapes, based on whether the filters agree to collide. (default null)
output nape.geom.RayResultList null A list to append results to instead of allocating a new one (default null)
Returns Description
nape.geom.RayResultList All valid results of ray cast in distance order from closest to furthest.

nape
new(?gravity: nape.geom.Vec2 = null, ?broadphase: Broadphase = null): Void

Construct a new Space object.

Name Type Default Description
gravity nape.geom.Vec2 null The gravity of this space. (default (0,0))
broadphase Broadphase null The broadphase type to use. (default DYNAMIC_AABB_TREE)

Private Members

Metadata

Name Parameters
:final -