Win an Ipad
  Developer   Documents   PhysicsContact

PhysicsContact

As you can see in the previous sample code, object of PhysicsContact class is the second parameter of PhysicsWorld.onBeginContact and PhysicsWorld.onEndContact functions.

This class contains properties like:

  • enabled
  • isTouching
  • densityA
  • densityB
  • frictionA
  • frictionB

and three important functions:

  • getBodyA()
  • getBodyB()  - to get bodies in contact
  • getNext() - to get next contact from actual contact list

 

this._world.onBeginContact = function(sender, contact)    {
       // set first contact object as current contact
       var current = contact;
       // repeat while any contact has been found
       while (current != null) {
           // get two bodies, which colide together
           var bodyA = current.getBodyA();
           var bodyB = current.getBodyB();
           // check if one of the badies was ball
           if (bodyA == this super._ball || bodyB == this super._ball)
               console<<"colision\n";
           // get next contact
           current = current.getNext();
       }
   };

 Game Engine   PhysicsContact   Game 
Write a Comment (0)
Subject
Please complete this mandatory field.
HTML Tags Not Allowed!
Comment
Please complete this mandatory field.