想用cocos2d-iphone+box2d做独轮车游戏目前用b2PolygonShape 建立一个矩形 然后一个b2CircleShape建立轮子 用b2RevoluteJointDef吧他们连接起来 能够转动,但感觉不自然 请问有没有什么好的方法啊?
- (void)createUniCycleWithCoords:(CGPoint)pos
{
b2BodyDef bd;
bd.type = b2_dynamicBody;
bd.position.Set(pos.x/PTM_RATIO, pos.y/PTM_RATIO);
bd.angularDamping = 5;
bd.linearDamping = 5;
truckBody = world->CreateBody(&bd);
b2PolygonShape shape;
b2FixtureDef fd;
fd.shape = &shape;
fd.density = 1;
fd.friction = 0.6;
fd.restitution = 0;
fd.filter.groupIndex = -1;
//
// // front axle and front spring
bd.position.Set(pos.x/PTM_RATIO, pos.y/PTM_RATIO);
//
frontAxle = world->CreateBody(&bd);
shape.SetAsBox(5.0/PTM_RATIO,
20.0/PTM_RATIO
);
frontAxle->CreateFixture(&fd);
// add two big wheels
{
float radius = 20.0f;
b2BodyDef bd;
bd.angularDamping = 5;
bd.type = b2_dynamicBody;
b2CircleShape shape;
shape.m_radius = radius/PTM_RATIO;
b2FixtureDef fd;
fd.shape = &shape;
fd.density = 0.5;
fd.friction = 10;
fd.restitution = 0;
fd.filter.groupIndex = -1;
// front wheel
bd.position.Set(frontAxle->GetWorldCenter().x,
frontAxle->GetWorldCenter().y-14*sin(M_PI/3)/PTM_RATIO);
frontWheel = world->CreateBody(&bd);
frontWheel->CreateFixture(&fd);
}
{
b2RevoluteJointDef rjd;
rjd.enableLimit = true;
rjd.enableMotor = true;
rjd.upperAngle = 180*M_PI/180;
rjd.lowerAngle = -180*M_PI/180;
rjd.Initialize(frontAxle, frontWheel, frontWheel->GetPosition());
frontMotor = (b2RevoluteJoint*)world->CreateJoint(&rjd);
}
}
-(void) createMenu
{
// Default font size will be 22 points.
;
// Reset Button
CCMenuItemLabel *reset = [CCMenuItemFont itemWithString:@"Reset" block:^(id sender){
;
}];
// to avoid a retain-cycle with the menuitem and blocks
// Achievement Menu Item using blocks
CCMenuItem *itemAchievement = [CCMenuItemFont itemWithString:@"Ceate Truck" block:^(id sender) {
CGSize winSize = winSize];
;
}];
// Leaderboard Menu Item using blocks
CCMenuItem *itemLeft = [CCMenuItemFont itemWithString:@"left" block:^(id sender) {
frontMotor->SetMotorSpeed(10 * -1);
frontMotor->SetMaxMotorTorque(12);
}];
CCMenuItem *itemRight = [CCMenuItemFont itemWithString:@"right" block:^(id sender) {
frontMotor->SetMotorSpeed(10 * 1);
frontMotor->SetMaxMotorTorque(14);
}];
CCMenu *menu = ;
;
CGSize size = winSize];
;
;
}