Moscrif API Docs for: 2012q3
Show:

PhysicsContact Class

include "lib://box2d/physicsContact.ms";
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. One instance of the PhysicsContact class can contains information about more contacts. An instanco of this class is usally created automatically, and pushed as a parameter onto functino, which react onto PhysicsScene/onBeginContact and PhysicsScene/onEndContact events.

Methods

this

(
  • world
  • nativeContact
)

Class constructor. Create an instance of physics contact. The PhysicsContact class is usually made automatically.

Parameters:

  • world PhysicsScene

    Instance of physics scene

  • nativeContact B2Contact

    Moscrif native instance of b2Contact

getBodyA

()

Get the first body in the contact.

Returns:

PhysicsSprite the first body in the contact

Example:

function beginContact(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 (there can be more contacts)
        current = current.getNext();
    }
}

getBodyB

()

Get the second body in the contact.

Returns:

PhysicsSprite The second body in the contact.

Example:

function beginContact(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 (there can be more contacts)
        current = current.getNext();
    }
}

getNext

()

Get the next contact in the contact list.

Returns:

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

Example:

function beginContact(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 (there can be more contacts)
        current = current.getNext();
    }
}

Properties

bounceA

Float

Bounce value of first object. The bounce value is usually set to be between 0 and 1. Consider dropping a ball on a table. A value of zero means the ball won't bounce. This is called an inelastic collision. A value of one means the ball's velocity will be exactly reflected. This is called a perfectly elastic collision. If collide two bodies with different bounce the box2d uses larger value to simulate the bounce.

bounceB

Float

Bounce value of second object. The bounce value is usually set to be between 0 and 1. Consider dropping a ball on a table. A value of zero means the ball won't bounce. This is called an inelastic collision. A value of one means the ball's velocity will be exactly reflected. This is called a perfectly elastic collision. If collide two bodies with different bounce the box2d uses larger value to simulate the bounce.

densityA

Float

Density of the first body in contact.

densityB

Float

Density of the second body in contact.

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 in contact..

frictionB

Float

Friction of the second body in contact.

isTouching

Boolean

Is this contact touching?

native

B2Contact

Moscrif native instance of b2Contact contained in the object of PhysicsContact class.