This API is used via wx.startAccelerometer(Object object).
interval
and the actual execution frequency of the wx.onAccelerometerChange callback function.Attribute | Type | Default value | Required | Description |
interval | string | normal | No | Execution frequency of the callback function for monitoring acceleration data |
success | function | - | No | Callback Function of Successful Interface Call |
fail | function | - | No | Callback Function of Failing Interface Call |
complete | function | - | No | Callback function executed upon the completion of the interface invocation (both successful and unsuccessful invocations) |
Value | Description |
game | Suitable for updating the callback frequency of the game, approximately every 20 ms. |
ui | Suitable for updating the callback frequency of the UI, approximately every 60 ms. |
normal | Regular callback frequency, approximately every 200 ms. |
wx.startAccelerometer({interval: 'game'})
This API is used via wx.stopAccelerometer(Object object).
Attribute | Type | Default value | Required | Description |
success | function | - | No | Callback Function of Successful Interface Call |
fail | function | - | No | Callback Function of Failing Interface Call |
complete | function | - | No | Callback function executed upon the completion of the interface invocation (both successful and unsuccessful invocations) |
wx.stopAccelerometer()
This API is used via wx.onAccelerometerChange(function listener).
Attribute | Type | Description |
x | number | X-axis |
y | number | Y-axis |
z | number | Z-axis |
wx.onAccelerometerChange(function (res) {console.log(res.x)console.log(res.y)console.log(res.z)})
This API is used via wx.offAccelerometerChange(function listener).
const listener = function (res) { console.log(res) }wx.onAccelerometerChange(listener)wx.offAccelerometerChange(listener) // The same function object as the listener must be passed in.
Was this page helpful?