地面体与地面之间的连接动态体(绳)

时间:2013-07-01 07:43:02

标签: iphone cocos2d-iphone

我正在实施一条悬挂在屏幕顶部的绳子,现在我已经使用一个动态的身体来制作绳索和我使用Revolute关节连接这个所有动态的身体来创造一根绳子。我成功地创造了绳索,现在当我试图将我的绳子连接在地面上时,它就没有固定在它上面。我猜它正在发生,因为我在绳索创作中使用了动态的身体。我正试图加入这个与距离联合,但它不起作用,我真的坚持这几周......请帮助。

绳索:

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&amp; amp;绳索:

 Distance joint :

b2DistanceJointDef jointDef;

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

>GetWorldCenter());

world->CreateJoint( &jointDef );  

这里,参考实体:groundbody ..链接:绳身

1 个答案:

答案 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 );