Robato
October 23, 2014, 1:30am
1
My Game uses the Accelerometer during a few sections of gameplay, but most of the time it doesn’t use it.
When I’m finished with it I try setting the interval to 0 with this function:
http://docs.coronalabs.com/api/library/system/setAccelerometerInterval.html
But I get an error:
Warning: …/menu.lua:1186: system.setAccelerometerInterval() frequency of 0 below minimum. Using minimum allowed frequency of 10 instead
This means the battery is still being drained. Is there anyway to turn off the accelerometer when you don’t need it anymore?
You can disable the accelerometer by removing your event listener like this…
Runtime:removeEventListener("accelerometer", onReceivedAccelerometerData)
Note that you must pass in the same listener/function into removeEventListener() that you originally provided to the addEventListener(). Once all listeners have been removed from the “accelerometer” event, Corona will disable the sensor.
Robato
October 23, 2014, 3:36am
3
You can disable the accelerometer by removing your event listener like this…
Runtime:removeEventListener("accelerometer", onReceivedAccelerometerData)
Note that you must pass in the same listener/function into removeEventListener() that you originally provided to the addEventListener(). Once all listeners have been removed from the “accelerometer” event, Corona will disable the sensor.
Thanks! I imagined that might work, but without the listener I couldn’t know for sure if it actually stopped
You can disable the accelerometer by removing your event listener like this…
Runtime:removeEventListener("accelerometer", onReceivedAccelerometerData)
Note that you must pass in the same listener/function into removeEventListener() that you originally provided to the addEventListener(). Once all listeners have been removed from the “accelerometer” event, Corona will disable the sensor.
Robato
October 23, 2014, 3:36am
5
You can disable the accelerometer by removing your event listener like this…
Runtime:removeEventListener("accelerometer", onReceivedAccelerometerData)
Note that you must pass in the same listener/function into removeEventListener() that you originally provided to the addEventListener(). Once all listeners have been removed from the “accelerometer” event, Corona will disable the sensor.
Thanks! I imagined that might work, but without the listener I couldn’t know for sure if it actually stopped