cocos2d-x之加速度传感器

cocos2d-x之加速度传感器

使用真机来调试

1 //加速度的默认状态是关闭的,需要手动的开启
2     Device::setAccelerometerEnabled(true);
3     
4     //auto listener = EventListenerAcceleration::create(const std::function<void (Acceleration *, Event *)> &callback);
5     //如何添加加速度的事件监听器,使用的是EventListenerAcceleration,
6     //他的穿进来的参数类型是个个函数,所以为了简写代码,都放在一起写了
7     Director::getInstance()->getEventDispatcher()->addEventListenerWithSceneGraphPriority(EventListenerAcceleration::create([](Acceleration *a, Event *e){
8         log("x:%g,y:%g,z:%g",a->x,a->y,a->z);//获取相关信息
9     }), this);
原文地址:https://www.cnblogs.com/dudu580231/p/4375314.html