I am currently working on a game and I have more Chipmunk objects and I am trying to drag them around.
Each object has touch enabled and I want to add a second body that will move when touch moved and link this body with the object body with a joint, therefore moving the object body.
This is what I do:
Code: Select all
touch began:
touchBody = cpBodyNew(1,1);
touchBody->p = touchLocation;
cpSpaceAddBody(space,touchBody);
joint = (cpConstraint*) cpPinJointInit(cpPinJointAlloc(), objBody, touchBody, ccp(0.5,0.5),ccp(0.5,0.5));
cpSpaceAddConstraint(space,joint);
touch moved:
touchBody->p = location;
touch ended:
destroy touch body
destroy constraint
Also, I would like the draggind to look a bit elastic (not rigid , the objBody should follow touchBody at a distance of max 10 pixels) but not like now...now the objBody hardly comes after touchBody, therefore getting a very large distance between them.
Do you have any ideas how I should do this?
Basically I want a cpMouse for each object. And I think my ideas is ok - making a new body and constraint when touch began, moving it when touch moved and destroying it when touch ended , but the drawback is the constraint which I don't fully understand.
Thank you.
Regards,
George