PhysicsContact Class
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.
Item Index
Methods
this
world
nativeContact
Class constructor. Create an instance of physics contact. The PhysicsContact class is usually made automatically.
Parameters:
-
world
PhysicsSceneInstance of physics scene
-
nativeContact
B2ContactMoscrif native instance of b2Contact
getBodyA
()
Get the first body in the contact.
Returns:
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:
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:
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.
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).
native
B2Contact
Moscrif native instance of b2Contact contained in the object of PhysicsContact class.