Accelerometer Interval?

Accelerometer Interval?
0.0 0


Hi. I’m struggling to set the update interval for the CCAccelerometer in Cocos2d-x with Box2d. Any help would be much appreciated.

Thank you.


Simple answer: You don’t.

Long answer: Use a fixed timestep for Box2D and use the accelerometer values that are available at a specific time instead. Not the other way around because that won’t work. A fixed timestep is also great for stabilizing Box2D output and other physics so it’s win anyway :slight_smile: You’ll never see any wonky physics anymore.

I’d give a link with more information, but Googling “fixed timestep” will provide you with much more (useful) results than I can list here.


Thanks! Just as I posted this I started looking at creating some kind of timed loop. For now I just added the accelerometer routines to my tick routine and it runs well across different devices now. I initially assumed that the CCAccelerometer had an updateInterval like the UIAccelerometer.


@io Meister
In fact, there is a parameter used to specify the “updateInterval” of Accelerometer when register the sensor listener.
But I don’t find a method to change the “updateInterval” dynamically.

In cocos2d-x, we use SENSOR_DELAY_GAME as the value of “updateInterval”.
You can manually modify the parameter of method registerListener in file

Hope it’s helpful!
By the way, if anyone know how to change the “updateInterval” dynamically on android, hope that you can share with us.


As far as I know you’ll have to re-register to modify the interval on Android.

But I wouldn’t trust the delay parameter. It’s not even guaranteed to be delayed for exactly the amount of time you’re asking for (ie. game, fastest, normal or ui). I believe it’s not even the same accross different devices.