Moscrif API Docs for: 2012q3
Show:

b2Contact Class

Library: box2d

The class manages contact between two shapes. A contact exists for each overlapping AABB in the broad-phase (except if filtered). Therefore a contact object may exist that has no contact points. An instance of this class is automatically created as a parameter of PhysicsScene/onBeginContact and PhysicsScene/onEndContact event.

Example:

this.onBeginContact = function(contact)
{
    // get the first contact
    var current = contact;
    while (current) {
        // get the bodies in the contact
        var bodyA = current.getBodyA();
        var bodyB = current.getBodyB();
        ...
        // get the next contact (they can be more contacts during the one step)
        current = current.getNext();
    }
}

Methods

getBodyA

() B2Contact

Get the first body in the contact.

Returns:

B2Contact: The first body in the contact

Example:

// handle all current contacts in the world
this._world.onBeginContact = function(sender, contact)
{
    // get the first body in the contact
    var bodyA = contact.getBodyA();
    // get the second body in the contact
    var bodyB = contact.getBodyB();
};

getBodyB

() B2Contact

Get the second body in the contact.

Returns:

B2Contact: The second body in the contact.

Example:

// handle all current contacts in the world
this._world.onBeginContact = function(sender, contact)
{
    // get the first body in the contact
    var bodyA = contact.getBodyA();
    // get the second body in the contact
    var bodyB = contact.getBodyB();
};

getNext

() B2Contact

Get the next contact in the world's contact list.

Returns:

B2Contact: Next contact in the list or null if no other is available.

Example:

// handle all current contacts in the world
....onBeginContact = function(contact)
{
    // set first contact to current
    var current = contact;
    // if there is no contact in current variable break the loop
    while (current != null)
    {
        // other operations with b2Contact object
        ...

        // get next contact
        current = current.getNext();
    }
};

Properties

densityA

Float

Density of the first body.

densityB

Float

Density of the second body.

enabled

Boolean

Enable/disable this contact. This can be used inside the pre-solve contact listener. The contact is only disabled for the current time step (or sub-step in continuous collisions).

frictionA

Float

Friction of the first body.

frictionB

Float

Friction of the second body.

isTouching

Boolean

Is this contact touching?

restitutionA

Float

Restitution of the first body.

restitutionB

Float

Restitution of the second body.