cocos2d-x之加速度传感器初试

时间:2024-10-12 09:04:08

bool HelloWorld::init()

{

if ( !Layer::init() )

{

return false;

}

Device::setAccelerometerEnabled(true);

Director::getInstance()->getEventDispatcher()->addEventListenerWithSceneGraphPriority(EventListenerAcceleration::create([](Acceleration *a,Event *e){

log("x:%g,y:%g,z:%g",a->x,a->y,a->z);

}),this);

return true;

}