cocos2d-x-3.2alpha0的物理世界。
hello 大家好,小弟这厢有礼了,我又来写博客了,cocos2d-x果然越来越人性话了。
看一看创建物理世界:
//创建一个物理场景
auto scene =Scene::createWithPhysics();
//设置物理世界的重力
scene->getPhysicsWorld()->setGravity(Vect(0,-(Director::getInstance()->getVisibleSize().height/3)));
//边界盒
auto edge=PhysicsBody::createEdgeBox(visibleSize);
对照一下cocos2d-x 2.2.3的Box2D
b2Vec2 gravity;
gravity.Set(0.0f, -10.0f); //重力
world = new b2World(gravity); //创建世界对象 一切都是映射
world->SetAllowSleeping(true); //允许休眠
world->SetContinuousPhysics(true); //设置检测连续碰撞
//定义地形钢体描述并设置坐标为左下角
b2BodyDef groundBodyDef;
groundBodyDef.position.Set(0, 0);
//根据钢体的描述创建钢体对象
b2Body* groundBody = world->CreateBody(&groundBodyDef);
groundBody->SetType(b2_staticBody);
b2EdgeShape groundBox; //定义地面盒形状
//2个点确定一条线,以下分别设置了屏幕的4个边
// bottom
groundBox.Set(b2Vec2(0, 0), b2Vec2(480/PTM_RATIO, 0));
groundBody->CreateFixture(&groundBox,0);
// top
groundBox.Set(b2Vec2(0 ,320/PTM_RATIO), b2Vec2(480/PTM_RATIO,320/PTM_RATIO));
groundBody->CreateFixture(&groundBox,0);
// left
groundBox.Set(b2Vec2(0, 320/PTM_RATIO), b2Vec2(0 ,0));
groundBody->CreateFixture(&groundBox,0);
// right
groundBox.Set(b2Vec2(480/PTM_RATIO, 320/PTM_RATIO), b2Vec2(480/PTM_RATIO, 0));
groundBody->CreateFixture(&groundBox,0);
CCSpriteBatchNode *blocks=CCSpriteBatchNode::create("blocks