码迷,mamicode.com
首页 > 其他好文 > 详细

cocos3 物理引擎

时间:2014-12-10 09:13:35      阅读:137      评论:0      收藏:0      [点我收藏+]

标签:style   blog   io   color   os   sp   on   div   log   

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 物理引擎

标签:style   blog   io   color   os   sp   on   div   log   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!