title: Cocos2d Box2d collision look ahead
body: <p>So I am trying to test collision in cocos2d-x with box2d. In my game loop I am moving the sprite and not using box2d physics. I do have it setup with a body in box2d so that I can have the rectangles right, however when it collides it is over lapping with the other object. I want it to stop where it collided at. I know why it is doing it (which is because it is told to move 8 points and the collision happens at 4) but I am not sure how to get it to stop exactly where it collides. If I do this:</p>
  
  <pre><code>float x = a-&gt;getPosition().x + (a-&gt;getContentSize().width / 2) + (b-&gt;getContentSize().width / 2);
  b-&gt;setPositionX(x);
  </code></pre>
  
  <p>It works but you can see it jump after it is done moving the 8 points and back 4 points. I am not sure if I am doing this completely wrong or what but I cant seem to get it to stop where it collided without jumping. Also just so you know what the update looks like:</p>
  
  <pre><code>Vec2 pos = _enemy-&gt;getPosition();
  pos.x -= _scrollSpeed;
  _enemy-&gt;setPosition(pos);
  </code></pre>
  
  <p>_scrollSpeed = 8 btw</p>
  
  <p>Any help is greatly appreciated.</p>