0

我正在实现一根悬挂在屏幕顶部的绳索,现在我使用一个动态体来创建绳索,并且我使用旋转关节来连接所有动态体以创建绳索。我成功地创建了绳索,现在当我尝试将我的绳索连接到地面时,它并没有固定在上面。我想这是因为我在绳索创作中使用的动态身体。我正在尝试通过距离关节加入这个,但它不起作用,我真的坚持了几个星期......请帮忙。

绳索:

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
}

GroundBody 和 Rope 之间的接头:

 Distance joint :

b2DistanceJointDef jointDef;

jointDef.Initialize(referencebody, link, referencebody->GetWorldCenter(), link-

>GetWorldCenter());

world->CreateJoint( &jointDef );  

在这里,referencebody : groundbody .. link : 绳体

4

1 回答 1

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 );
于 2013-07-01T11:26:42.953 回答