Search code examples
c++iphonecocos2d-iphonebox2d

Drag Box2d Bodies on Touch


I have two box2d bodies, one is static and other is dynamic. Now i have joined the static body with dynamic body through b2revoluteJoint. So my question is:

1) How do i move Dynamic Body on touchMoved along with static body which is attached at the same position on the dynamic body.

2) How do i move more than two bodies. Let suppose i have a human body, and the legs and hands are joined with b2RevoluteJoint. Now how can i move all the bodies together to create a natural look.

I am completely new in box2d so having some difficulties. Any one please help me regarding this issue.Thanks!


Solution

  • 1) For dragging objects in box2d is mouseJoint. In touchBegan you create a mouse joint with object that you want move and any static body for example groundBody, but in this joint this can be every static body. In touchMoved you change the position of mouseJoint. In touchEnded destroy joint :)

    2) you can create more revoluteJoints for example leg and main body are jointed and arm and main body are jointed too.