1.创建一个物理scene
Scene* HelloWorld::createScene()
{
auto scene = Scene::createWithPhysics();
auto layer = HelloWorld::create();
scene->addChild(layer);
return scene;
}
调试开关
scene->getPhysicsWorld()->setDebugDrawMask(PhysicsWorld::DEBUGDRAW_ALL);
2.创建一个世界
Size size = Director::getInstance()->getWinSize();
auto edgeSp = Sprite::create();
auto boundBody = PhysicsBody::createEdgeBox(size, PHYSICSBODY_MATERIAL_DEFAULT, 2);
edgeSp->setPosition(Point(size.width / 2, size.height / 2));
edgeSp->setPhysicsBody(boundBody);
this->addChild(edgeSp);
3.创建一个有物理属性的精灵
Sprite m_ball = Sprite::create("ball.png");
m_ball->setPosition(100,100);
auto body = PhysicsBody::createCircle(