cocos3 初识物理引擎

Scene* HelloWorld::createScene()
{
    // 'scene' is an autorelease object
    auto scene = Scene::createWithPhysics();
    scene->getPhysicsWorld()->setDebugDrawMask(PhysicsWorld::DEBUGDRAW_ALL);
    // 'layer' is an autorelease object
    auto layer = HelloWorld::create();

    // add layer as a child to scene
    scene->addChild(layer);

    // return the scene
    return scene;
}

 

 

void HelloWorld::onEnter()
{
    Layer::onEnter();
    addEdge();
}

 

 

void HelloWorld::addEdge()
{
    Size visibleSize=Director::getInstance()->getVisibleSize();
    auto body=PhysicsBody::createEdgeBox(visibleSize);

    auto node=Node::create();
    node->setPhysicsBody(body);
    node->setPosition(visibleSize.width/2,visibleSize.height/2);
    addChild(node);

}

 

posted @ 2014-12-09 20:59  yufenghou  阅读(121)  评论(0编辑  收藏  举报