cocos2d 作为游戏引擎,提供了基本的模拟现实物理世界中的一些属性,比如物体有摩擦力,重力,加速度,角速度等等
这里简单介绍一下cocos2dx 物理世界里面的碰撞检测
启用physicsWorld
Scene* HelloWorld::createScene()
{
// 'scene' is an autorelease object
//auto scene = Scene::create();
// 创建带物理特性的场景
auto scene = Scene::createWithPhysics();
scene->getPhysicsWorld()->setGravity(Vec2(0, 0));// 设置重力,是x,y 方向合成的,比如 x=0,y=-980,则是竖直向下的
//scene->getPhysicsWorld()->setAutoStep(false);//这个是为了避免物体间接触,不定时的发生跳动的情况,但是有些电脑上不加也不会出现问题
//scene->getPhysicsWorld()->setDebugDrawMask(PhysicsWorld::DEBUGDRAW_ALL);// 这个是为了方便开发时调试,将所有body的边框显示出来
// 'layer' is an autorelease object
auto layer = HelloWorld::create();
// add layer as a child to scene
scene->addChild(layer