Skip to content

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。
    PropertiesTypeDefault valueRequiredDescription
    intervalstringnormalNoMonitor the execution frequency of the gyroscope data callback function
    successFunction-NoCallback function for successful interface call
    failFunction-NoCallback function for failed interface call
    completeFunction-NoCallback function for interface call completion (executed regardless of success or failure)
  • The legal value of object.interval
    ValueDescription
    gameThe callback frequency suitable for updating the game is about 20ms/time
    uiThe callback frequency suitable for updating the UI is about 60ms/time
    normalThe 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。
    PropertiesTypeDefault valueRequiredDescription
    successFunction-NoCallback function for successful interface call
    failFunction-NoCallback function for failed interface call
    completeFunction-NoCallback 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:
    PropertiesTypeDescription
    xnumberAngular velocity of the x-axis
    ynumberAngular velocity of the y-axis
    znumberAngular 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.