tencent cloud

Feedback

Accelerometer

Last updated: 2024-11-21 18:48:11

    starAccelerometer

    This API is used via wx.startAccelerometer(Object object).
    Note:
    Depending on the performance of the device, as well as the current CPU and memory usage, there may be some discrepancies between the set interval and the actual execution frequency of the wx.onAccelerometerChange callback function.
    Feature Description: Starts monitoring acceleration data.
    Parameter and Description: Object.
    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)
    Valid values of object.interval
    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.
    Sample Code
    wx.startAccelerometer({
    interval: 'game'
    })

    stopAccelerometer

    This API is used via wx.stopAccelerometer(Object object).
    Feature Description: Stops monitoring acceleration data.
    Parameter and Description: 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)
    Sample Code
    wx.stopAccelerometer()

    onAccelerometerChange

    This API is used via wx.onAccelerometerChange(function listener).
    Feature Description: Monitor acceleration data events. The frequency depends on the interval parameter of wx.startAccelerometer(). The monitoring can be stopped using wx.stopAccelerometer().
    Parameter and Description: Function callback.
    The callback function for acceleration data events:
    Attribute
    Type
    Description
    x
    number
    X-axis
    y
    number
    Y-axis
    z
    number
    Z-axis
    Sample Code
    wx.onAccelerometerChange(function (res) {
    console.log(res.x)
    console.log(res.y)
    console.log(res.z)
    })

    offAccelerometerChange

    This API is used via wx.offAccelerometerChange(function listener).
    Feature Description:
    Parameters and Description: function listener, the listening function passed into onAccelerometerChange. If this parameter is not provided, all listening functions will be removed.
    Sample Code
    const listener = function (res) { console.log(res) }
    
    wx.onAccelerometerChange(listener)
    wx.offAccelerometerChange(listener) // The same function object as the listener must be passed in.
    
    Contact Us

    Contact our sales team or business advisors to help your business.

    Technical Support

    Open a ticket if you're looking for further assistance. Our Ticket is 7x24 avaliable.

    7x24 Phone Support