I can't find the tutorials of joints class in the Box2D for iPhone. I am unable to run a Testbed for iPhone Box2D.
(void)ccTouchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
if (_mouseJoint!=NULL)return;
UITouch *mytouch=[touches anyObject];
CGPoint location=[mytouch locationInView:[mytouch view]];
location=[[CCDirector sharedDirector]convertToGL:location];
b2Vec2 locationWorld=b2Vec2(location.x/PTM_RATIO,location.y/PTM_RATIO);
//ristrict the player within the ground limit keep stucking the player with grounditself.....
if (_playerFixture->TestPoint(locationWorld))
{
b2MouseJointDef md;
md.bodyA=groundBody;
md.bodyB=_playerBody;
md.target=locationWorld;
md.collideConnected=true;
md.maxForce=100.0f*_playerBody->GetMass();
_mouseJoint=(b2MouseJoint *)_world->CreateJoint(&md);
_playerBody->SetAwake(true);
}
}
-(void)ccTouchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
if (_mouseJoint == NULL) return;
UITouch *myTouch = [touches anyObject];
CGPoint location = [myTouch locationInView:[myTouch view]];
location = [[CCDirector sharedDirector] convertToGL:location];
if (location.y<240.00&&location.y>=20.0f)
{
b2Vec2 locationWorld = b2Vec2(location.x/PTM_RATIO, location.y/PTM_RATIO);
_mouseJoint->SetTarget(locationWorld);
}
}
- (void)ccTouchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
if (_mouseJoint)
{
_world->DestroyJoint(_mouseJoint);
_mouseJoint = NULL;
}
}
