destroying a weldjoint at a sprite's specific position

I have created a weldJoint between two sprites in my code (see update method below) and I also created a method that returns the exact position of a sprite when a mouseJoint is released. I want to compare the current position of the sprite to the spritePositionRelease value and destroy the weldJoint if the y values are the same and x values are different. Please help.

spritePositionRelease:

Code: Select all

- (CGPoint)spritePositionRelease    {

for(b2Body *b = mouseJoint->GetBodyB(); b; b=b->GetNext())    {
    if (b->GetUserData() != NULL)
    {
        CCSprite *mySprite = (CCSprite*)b->GetUserData();
        if (mySprite.tag == 1) {
            mySprite.position = CGPointMake( b->GetPosition().x * PTM_RATIO, b->GetPosition().y * PTM_RATIO);
            CGPoint spritePosition = mySprite.position;
            CCLOG(@"the sprite position is x:%0.2f , y:%0.2f", spritePosition.x, spritePosition.y);

            return spritePosition;

        }
    }
}
}


ccTouchesEnded:

Code: Select all

- (void)ccTouchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{

if (mouseJoint)
{
    [self spritePositionRelease];

    world->DestroyJoint(mouseJoint);
    mouseJoint = NULL;
}
}


update:

Code: Select all

-(void) update: (ccTime) dt
{
//It is recommended that a fixed time step is used with Box2D for stability
//of the simulation, however, we are using a variable time step here.
//You need to make an informed choice, the following URL is useful
//http://gafferongames.com/game-physics/fix-your-timestep/

int32 velocityIterations = 8;
int32 positionIterations = 1;

// Instruct the world to perform a single step of simulation. It is
// generally best to keep the time step and iterations fixed.
world->Step(dt, velocityIterations, positionIterations);

// using the iterator pos over the set
std::set<BodyPair *>::iterator pos;

for(pos = bodiesForJoints.begin(); pos != bodiesForJoints.end(); ++pos)
{
    b2WeldJoint         *weldJoint;
    b2WeldJointDef      weldJointDef;

    BodyPair            *bodyPair = *pos;
    b2Body              *bodyA = bodyPair->bodyA;
    b2Body              *bodyB = bodyPair->bodyB;

    weldJointDef.Initialize(bodyA,
                            bodyB,
                            bodyA->GetWorldCenter());

    weldJointDef.collideConnected = false;
    weldJoint = (b2WeldJoint*) world->CreateJoint(&weldJointDef);

    // Free the structure we allocated earlier.
    free(bodyPair);

    // Remove the entry from the set.
    bodiesForJoints.erase(pos);
}

} 

Original thread: https://box2d.org/forum/viewtopic.php?t=8746