绳索:
b2Body* link;
CGSize s = [CCDirector sharedDirector].winSize;
CGFloat linkHeight = 0.24;
CGFloat linkWidth = 0.1;
link = world->CreateBody( &bodyDef );
link->CreateFixture( &fixtureDef );
PhysicsSprite* segmentSprite = [PhysicsSprite spriteWithFile:@"rope_seg_new2.png"];
[self addChild:segmentSprite];
[segmentSprite setPhysicsBody:link];
//set up the common properties of the joint before entering the loop
revoluteJointDef.localAnchorA.Set( 0, linkHeight);
revoluteJointDef.localAnchorB.Set( 0, -linkHeight);
//use same definitions to create multiple bodies
for (int i = 0; i < 10 ; i++) {
newLink = world->CreateBody( &bodyDef );
newLink->CreateFixture( &fixtureDef );
PhysicsSprite* segmentSprite = [PhysicsSprite spriteWithFile:@"rope_seg_new2.png"];
[self addChild:segmentSprite];
[segmentSprite setPhysicsBody:link];
revoluteJointDef.bodyA = link;
revoluteJointDef.bodyB = newLink;
world->CreateJoint( &revoluteJointDef );
link = newLink; //prepare for next iteration
}
Distance joint :
b2DistanceJointDef jointDef;
jointDef.Initialize(referencebody, link, referencebody->GetWorldCenter(), link-
>GetWorldCenter());
world->CreateJoint( &jointDef );
这里,参考实体:groundbody ..链接:绳身
答案 0 :(得分:0)
我通过Revolute联合回答......
b2RevoluteJointDef revoluteJointDef;
revoluteJointDef.bodyA = referenceBody;
revoluteJointDef.bodyB = lastLink;
revoluteJointDef.localAnchorA = startPos;//world coords, because m_groundBody is at (0,0)
revoluteJointDef.localAnchorB.Set(0,0);//center of circle
world->CreateJoint( &revoluteJointDef );