Search code examples
cocos2d-iphonephysicsshapeschipmunk

cocos2d two physics bodies move together (chipmunk)


the cocos2d tank As the picture shows. How can I make part A stick intensely with part B ? to make a tank body ?

contex shape is OK but cancerve is not . so I want to make two parts stick together and move....

Thanks in advance. PS I am using cocos2d v3 , it is chipmunk encapsulated with cocos2d, no Box2D here..

=============

Now I have resolved the issue . use Shapes list can do . But new questions comes : how can I put the gun on tank ? pivot body can rotate some angle but not 360.

there are only 4 connects in CCPhysicsJoint:

+(CCPhysicsJoint *)connectedPivotJointWithBodyA:(CCPhysicsBody *)bodyA bodyB:(CCPhysicsBody *)bodyB anchorA:(CGPoint)anchorA;

+(CCPhysicsJoint *)connectedDistanceJointWithBodyA:(CCPhysicsBody *)bodyA bodyB:(CCPhysicsBody *)bodyB
    anchorA:(CGPoint)anchorA anchorB:(CGPoint)anchorB;

+(CCPhysicsJoint *)connectedDistanceJointWithBodyA:(CCPhysicsBody *)bodyA bodyB:(CCPhysicsBody *)bodyB
    anchorA:(CGPoint)anchorA anchorB:(CGPoint)anchorB
    minDistance:(CGFloat)min maxDistance:(CGFloat)max;

+(CCPhysicsJoint *)connectedSpringJointWithBodyA:(CCPhysicsBody *)bodyA bodyB:(CCPhysicsBody *)bodyB
    anchorA:(CGPoint)anchorA anchorB:(CGPoint)anchorB
    restLength:(CGFloat)restLength stiffness:(CGFloat)stiffness damping:(CGFloat)damping;

no one fit.

And my question is , can I rotate a angle on a shape in shape-arranged body ?


Solution

  • You can create a body with multiple shapes attached. http://www.cocos2d-iphone.org/docs/api/Classes/CCPhysicsBody.html#//api/name/bodyWithShapes: