0

こんにちは皆さん、私は cocos2d v1 でゲームを開発しており、box2d を使用しています。Retinaディスプレイを有効にしています。バケットを作成しています。バケツを x 軸だけに動かしたいので、b2PrismaticJoint を実行しましたが、問題はバケツが地面に合わないことです。これが私のコードです: `CCSprite *tube = [CCSprite spriteWithFile:@"tube.png"]; tube.position = ccp(SCREEN_WIDTH/2, SCREEN_HEIGHT/2); [self addChild:tube];

b2BodyDef bucketBodyDef;
bucketBodyDef.type = b2_dynamicBody;
bucketBodyDef.position.Set(tube.contentSize.width/PTM_RATIO, tube.contentSize.height/PTM_RATIO);
bucketBodyDef.userData = tube;
tubeBody = world->CreateBody(&bucketBodyDef);

b2PolygonShape bucketShape;
bucketShape.SetAsBox(tube.contentSize.width/2/PTM_RATIO, tube.contentSize.height/2/PTM_RATIO);


// Create shape definition and add to body
b2FixtureDef bucketShapeDef;
bucketShapeDef.shape = &bucketShape;
bucketShapeDef.density = 10.0f;
bucketShapeDef.friction = 0.4f;
tubeFixture = tubeBody->CreateFixture(&bucketShapeDef);


[self createTubeFixtures];


// Restrict bucket along the x axis
b2PrismaticJointDef jointDef;
b2Vec2 worldAxis(1.0f, 0.0f);
jointDef.collideConnected = true;
jointDef.Initialize(tubeBody, groundBody,
                    tubeBody->GetWorldCenter(), worldAxis); 
world->CreateJoint(&jointDef);`

ジョイントを外すとすべて良好です。添付の​​写真をご覧ください。ありがとう!

ジョイント付

ジョイントなし

4

1 に答える 1

0

I did a little mistake that's cost me two days!! and that was on setting the coordinates of the body : b2BodyDef bucketBodyDef; bucketBodyDef.type = b2_dynamicBody; **bucketBodyDef.position.Set(tube.contentSize.width/2/PTM_RATIO, tube.contentSize.height/2/PTM_RATIO);** bucketBodyDef.userData = tube; tubeBody = world->CreateBody(&bucketBodyDef);

于 2013-04-03T20:33:50.170 に答える