【发布时间】:2014-12-12 09:57:56
【问题描述】:
如何在 cocos2d-x 3.3 中将这两个(汽车和车轮)结合为一个物理体? 如何将此关节体添加到物理世界中?
Sprite *car=Sprite::create("abc.png");
car->setPosition(100,400);
car->setScale(1.5, 1.5);
this->addChild(car);
PhysicsBody *car_body=PhysicsBody::create();
car->setPhysicsBody(car_body);
car_body->setGravityEnable(false);
Sprite *wheel=Sprite::create("abc.png");
wheel->setPosition(40,350);
this->addChild(wheel);
PhysicsBody *wheel_bd=PhysicsBody::create();
wheel_bd=PhysicsBody::createCircle(69.0/64.0);
wheel->setPhysicsBody(wheel_bd);
wheel_bd->setGravityEnable(false);
PhysicsJoint *co =PhysicsJointGroove::construct(wheel->getPhysicsBody(),
car->getPhysicsBody(),Vec2(80,250),Vec2(160,250),Vec2(1.0,1.0));
scene->getPhysicsWorld()->addJoint(co); //this line creating error into my code.
【问题讨论】:
-
因为世界是空的,你必须通过场景将世界传递到这一层
-
谢谢兄弟...我是 PhysicsPrograming 的新手。如何将世界传递到层?上面的身体联合正确吗?
标签: cocos2d-x box2d cocos2d-x-3.0 chipmunk