19.9.4 addCollisionHandler

self = physics.Space:addCollisionHandler(collisionTypeA,collisionTypeB, 
                                                callbacksTable)

Parameter

Type

Description

self

in physics.Space

The input simulation Space

collisionTypeA

in number

Type of first collision

collisionTypeB

in number

Type of second collision

callbacksTable

in table of functions

A table of functions to call during collision detection and handling

self

out physics.Space

The input Space is returned as the output

Registers a table of callback functions to handle collisions between shapes of collisionTypeA and shapes of collisionTypeB. Listing 19.3 shows the form of the callbacksTable.

Listing 19.3: The Form of the Callback Table for physics.Space:addCollisionHandler()

{ 
    begin = function(arbiter, space, callbacksTable) ... end,
    preSolve = function(arbiter, space, callbacksTable) ... end,
    postSolve = function(arbiter, space, callbacksTable) ... end,
    separate = function(arbiter, space, callbacksTable) ... end
}

If the begin handler or preSolve handler return false, further collision calculations are bypassed. If they return true, the collision processing proceeds as normal.

It is not necessary to provide handlers for all callback table entries. Default handling will be provided for unspecified handlers.

Returns self.

See http://chipmunk-physics.net/release/Chipmunk-5.x/Chipmunk-5.3.4-Docs/ for an explanation of collision processing and collision handler callbacks.

One important point to note is that these callback handlers must not add or remove Bodies, Shapes, or Constraints from the Space

See the post-step callback functions for the right way to remove (or add) objects as the result of a collision.

Introduced in platform.apiLevel = '2.0'