title: tracking a sprite body position as it moves
body: <p>This might sound quite straightforward. I want to keep track of a sprite body position only AFTER it has been moved by a mouseJoint so I can limit it's movement by comparing it's position (at any given time after mouseJoint is released) with a given position. Please help.</p>
  
  <p><strong>UPDATED</strong></p>
  
  <p>Here's what I did. I made a method that returns the sprite's position, which I called in the ccTouchesEnded method:</p>
  
  <pre><code>- (CGPoint)spritePositionRelease    {
  
  for(b2Body *b = mouseJoint-&gt;GetBodyB(); b; b=b-&gt;GetNext())    {
      if (b-&gt;GetUserData() != NULL)
      {
          CCSprite *mySprite = (CCSprite*)b-&gt;GetUserData();
          if (mySprite.tag == 1) {
              mySprite.position = CGPointMake( b-&gt;GetPosition().x * PTM_RATIO, b-&gt;GetPosition().y * PTM_RATIO);
              spritePosition = mySprite.position;
              CCLOG(@"the sprite position is x:%0.2f , y:%0.2f", spritePosition.x, spritePosition.y);
  
              return spritePosition;
          }
      }
  }
  }
  </code></pre>
  
  <p>ccTouchesEnded:</p>
  
  <pre><code>- (void)ccTouchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
  {
  
  if (mouseJoint)
  {
      [self spritePositionRelease];
      world-&gt;DestroyJoint(mouseJoint);
      mouseJoint = NULL;
  }
  }
  </code></pre>
  
  <p>In the tick method I added the following code:</p>
  
  <pre><code>        for(b2Body *b = world-&gt;GetBodyList(); b; b=b-&gt;GetNext())    {
          if (b-&gt;GetUserData() != NULL)
          {
              CCSprite *mySprite = (CCSprite*)b-&gt;GetUserData();
              if (mySprite.tag == 1) {
                  mySprite.position = CGPointMake( b-&gt;GetPosition().x * PTM_RATIO, b-&gt;GetPosition().y * PTM_RATIO);
                  CGPoint spriteCurrentPosition = mySprite.position;
  
                  if ( spritePosition.x != spriteCurrentPosition.x &amp;&amp; 
                       spritePosition.y == spriteCurrentPosition.y) {
                      CCLOG(@"the sprite limit for y is y:%0.2f has been reached",  spriteCurrentPosition.y);
                  }
              }
          }
      }
  </code></pre>
  
  <p>I initialized the spritePosition in the HelloWorldLayer.h class. I know I've done something wrong. I don't think the spritePosition I am accessing in the tick method has the same value as the spritePosition in the ccTouchesEnded method, hence the condition in the tick method never gets satisfied. I am not sure how to get this corrected. Please help</p>