title: Contact listener in Box2d Cocos2d
body: <p>i want to rotate a sprite and move forward after a collisions occurs with a object.
  The collision has to be using Box2d since i need pixel perfect collision. 
  i have the header and implementation class for contactlistener but how do i implement it in the main class ? </p>
  
  <p>my .h file for contact listener is </p>
  
  <pre><code> #import "Box2D.h"
   #import &lt;vector&gt;
   #import &lt;algorithm&gt;
  
  struct MyContact {   
      b2Fixture *fixtureA;   
  b2Fixture *fixtureB;   
  bool operator==(const MyContact&amp; other) const  
  {  
      return (fixtureA == other.fixtureA) &amp;&amp; (fixtureB == other.fixtureB);  
  }  
  };
  class MyContactListener : public b2ContactListener {
  
  public:
  std::vector&lt;MyContact&gt;_contacts;
  
  MyContactListener();
  ~MyContactListener();
  
  virtual void BeginContact(b2Contact* contact);
  virtual void EndContact(b2Contact* contact);
  virtual void PreSolve(b2Contact* contact, const b2Manifold* oldManifold);    
  virtual void PostSolve(b2Contact* contact, const b2ContactImpulse* impulse);
  
  };
  </code></pre>
  
  <p>This is my .M file for contact listener </p>
  
  <pre><code>    #import "MyContactListener.h"
  
  MyContactListener::MyContactListener() : _contacts() {    
  }    
  
  MyContactListener::~MyContactListener() {    
  }    
  
  void MyContactListener::BeginContact(b2Contact* contact) {    
      // We need to copy out the data because the b2Contact passed in    
  // is reused.    
  MyContact myContact = { contact-&gt;GetFixtureA(), contact-&gt;GetFixtureB() };     
  _contacts.push_back(myContact);     
  }     
  
  void MyContactListener::EndContact(b2Contact* contact) {     
      MyContact myContact = { contact-&gt;GetFixtureA(), contact-&gt;GetFixtureB() };    
      std::vector&lt;MyContact&gt;::iterator pos;    
      pos = std::find(_contacts.begin(), _contacts.end(), myContact);    
      if (pos != _contacts.end()) {    
          _contacts.erase(pos);    
      }    
  }    
  
  void MyContactListener::PreSolve(b2Contact* contact, const b2Manifold* oldManifold) {    
  }     
  
  void MyContactListener::PostSolve(b2Contact* contact, const b2ContactImpulse* impulse) {    
  }     
  </code></pre>
  
  <p>In the main class i have </p>
  
  <pre><code>contactListner = new MyContactListener;
  world-&gt;SetContactListener(contactListner);
  </code></pre>
  
  <p>After this how do i check for collision in the scheduler method ?</p>
  
  <p>Thanks for the help </p>