首页 > 其他 > 详细

cocos3 物理引擎

时间:2014-12-10 09:10:51      阅读:148      评论:0      收藏:0      [点我收藏+]
Scene* HelloWorld::createScene()
{
    auto scene = Scene::createWithPhysics();
    scene->getPhysicsWorld()->setDebugDrawMask(PhysicsWorld::DEBUGDRAW_ALL);

    auto layer = HelloWorld::create();

    scene->addChild(layer);

    return scene;
}

bool HelloWorld::init()
{

    if ( !Layer::init() )
    {
        return false;
    }

    Size size = Director::getInstance()->getVisibleSize();
    Vec2 origin = Director::getInstance()->getVisibleOrigin();

    return true;
}

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

void HelloWorld::addEdge()
{
    Size size = Director::getInstance()->getVisibleSize();
    Size liteSize=size;
    liteSize.width-=10;
    liteSize.height-=20;
    auto edgeBox=PhysicsBody::createEdgeBox(liteSize);

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

void HelloWorld::addBall()
{
    Size size = Director::getInstance()->getVisibleSize();
    auto ball=Sprite::create("ball.png");
    ball->setPosition(size.width/2,size.height/2);
    ball->setPhysicsBody(PhysicsBody::createBox(ball->getContentSize()));
    addChild(ball);

}

 

cocos3 物理引擎

原文:http://www.cnblogs.com/yufenghou/p/4154596.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!