On this page
Gyroscope
startGyroscope
TIP
The API usage is as follows: wx.startGyroscope(Object object)
- Functional description: Start listening for gyroscope data
- Parameters and descriptions: Object object。
Properties Type Default value Required Description interval string normal No Monitor the execution frequency of the gyroscope data callback function success Function - No Callback function for successful interface call fail Function - No Callback function for failed interface call complete Function - No Callback function for interface call completion (executed regardless of success or failure) - The legal value of object.interval
Value Description game The callback frequency suitable for updating the game is about 20ms/time ui The callback frequency suitable for updating the UI is about 60ms/time normal The normal callback frequency is about 200ms/time
stopGyroscope
TIP
The API usage is as follows: wx.stopGyroscope(Object object)
- Functional description: Stop listening for gyroscope data
- Parameters and descriptions: Object object。
Properties Type Default value Required Description success Function - No Callback function for successful interface call fail Function - No Callback function for failed interface call complete Function - No Callback function for interface call completion (executed regardless of success or failure)
onGyroscopeChange
TIP
The API usage is as follows: wx.onGyroscopeChange(function callback)
- Functional description: Monitor gyroscope data change events. The frequency is based on wx.startGyroscope() interval parameter. You can use wx.stopGyroscope() Stops monitoring.
- Parameters and descriptions: function callback, The callback function of the acceleration data event. The parameters Object.res are as follows:
Properties Type Description x number Angular velocity of the x-axis y number Angular velocity of the y-axis z number Angular velocity of the z-axis
offGyroscopeChange
TIP
The API usage is as follows: wx.offGyroscopeChange(function listener)
Functional description: Remove the listener function for gyroscope data change events
Parameters and descriptions: function listener, Listener function passed in by onGyroscopeChange. If this parameter is not passed, all listeners will be removed
Sample code:
js
const listener = function (res) { console.log(res) }
wx.onGyroscopeChange(listener)
wx.offGyroscopeChange(listener) // Pass the same function object used for listening.