new Space()
- Source:
Basic Unit of Simulation in Chipmunk
Methods
addBody(body) → {cp.Body}
- Source:
Add a rigid body to the simulation.
Parameters:
Returns:
-
Type
-
cp.Body
addCollisionHandler(a, b, begin, preSolve, postSolve, separate)
- Source:
Set a collision handler to be used whenever the two shapes with the given collision types collide.
You can pass null for any function you don't want to implement.
Parameters:
Name |
Type |
Description |
a |
number
|
Collision Type. |
b |
number
|
Collision Type. |
begin |
function
|
null
|
Two shapes just started touching for the first time this step.
Return true from the callback to process the collision normally or false to cause Chipmunk to ignore the collision entirely.
If you return false, the preSolve() and postSolve() callbacks will never be run, but you will still recieve a separate event when the shapes stop overlapping. |
preSolve |
function
|
null
|
Two shapes are touching during this step.
Return false from the callback to make Chipmunk ignore the collision this step or true to process it normally.
Additionally, you may override collision values using cpArbiterSetFriction(), cpArbiterSetElasticity() or cpArbiterSetSurfaceVelocity() to provide custom friction, elasticity, or surface velocity values. |
postSolve |
function
|
null
|
Two shapes are touching and their collision response has been processed.
You can retrieve the collision impulse or kinetic energy at this time if you want to use it to calculate sound volumes or damage amounts. |
separate |
function
|
null
|
Two shapes have just stopped touching for the first time this step.
To ensure that begin()/separate() are always called in balanced pairs, it will also be called when removing a shape while its in contact with something or when deallocating the space. |
addConstraint(constraint) → {cp.Constraint}
- Source:
Add a constraint to the simulation.
Parameters:
Name |
Type |
Description |
constraint |
cp.Constraint
|
|
Returns:
-
Type
-
cp.Constraint
addShape(shape) → {cp.Shape}
- Source:
Add a collision shape to the simulation.
If the shape is attached to a static body, it will be added as a static shape.
Parameters:
Returns:
-
Type
-
cp.Shape
addStaticShape(shape) → {cp.Shape}
- Source:
Explicity add a shape as a static shape to the simulation.
Parameters:
Returns:
-
Type
-
cp.Shape
containsBody(body) → {boolean}
- Source:
Test if a rigid body has been added to the space.
Parameters:
Returns:
-
Type
-
boolean
containsConstraint(constraint) → {bool}
- Source:
Test if a constraint has been added to the space.
Parameters:
Name |
Type |
Description |
constraint |
cp.Constraint
|
|
Returns:
-
Type
-
bool
containsShape(shape) → {boolean}
- Source:
Test if a collision shape has been added to the space.
Parameters:
Returns:
-
Type
-
boolean
eachBody(func)
- Source:
Call func for each body in the space.
Parameters:
Name |
Type |
Description |
func |
function
|
|
eachConstraint(func)
- Source:
Call func for each shape in the space.
Parameters:
Name |
Type |
Description |
func |
function
|
|
eachShape(func)
- Source:
Call func for each shape in the space.
Parameters:
Name |
Type |
Description |
func |
function
|
|
filterArbiters(body, filter) → {Arbiter}
- Source:
Parameters:
Returns:
-
Type
-
Arbiter
getCurrentTimeStep() → {number}
- Source:
Returns:
-
Type
-
number
isLocked()
- Source:
returns true from inside a callback and objects cannot be added/removed.
Parameters:
lookupHandler(a, b) → {CollisionHandler}
- Source:
Parameters:
Name |
Type |
Description |
a |
number
|
|
b |
number
|
|
Returns:
-
Type
-
CollisionHandler
reindexShape(shape)
- Source:
Update the collision detection data for a specific shape in the space.
Parameters:
reindexShapesForBody(body)
- Source:
Update the collision detection data for all shapes attached to a body.
Parameters:
reindexStatic()
- Source:
Update the collision detection info for the static shapes in the space.
removeBody(body)
- Source:
Remove a rigid body from the simulation.
Parameters:
removeCollisionHandler(a, b)
- Source:
Unset a collision handler.
Parameters:
Name |
Type |
Description |
a |
number
|
Collision Type. |
b |
number
|
Collision Typel |
removeConstraint(constraint)
- Source:
Remove a constraint from the simulation.
Parameters:
Name |
Type |
Description |
constraint |
cp.Constraint
|
|
removeShape(shape)
- Source:
Remove a collision shape from the simulation.
Parameters:
removeStaticShape(shape)
- Source:
Remove a collision shape added using addStaticShape() from the simulation.
Parameters:
setDefaultCollisionHandler(begin, preSolve, postSolve, separate)
- Source:
Set a default collision handler for this space.
The default collision handler is invoked for each colliding pair of shapes
that isn't explicitly handled by a specific collision handler.
You can pass null for any function you don't want to implement.
Parameters:
Name |
Type |
Description |
begin |
function
|
null
|
|
preSolve |
function
|
null
|
|
postSolve |
function
|
null
|
|
separate |
function
|
null
|
|
setIterations(iter)
- Source:
Parameters:
Name |
Type |
Description |
iter |
number
|
|
uncacheArbiter(arb)
- Source:
Parameters:
useSpatialHash(dim, count)
- Source:
Switch the space to use a spatial has as it's spatial index.
Parameters:
Name |
Type |
Description |
dim |
|
|
count |
|
|