cocos2d-x 3.2 物理世界PhysicsWorld

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
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值