tencent cloud

All product documents
Tencent Cloud Super App as a Service
Accelerometer
Last updated: 2025-02-24 17:10:36
Accelerometer
Last updated: 2025-02-24 17:10:36

startAccelerometer

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.

Was this page helpful?
You can also Contact Sales or Submit a Ticket for help.
Yes
No

Feedback

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 available.

7x24 Phone Support
Hong Kong, China
+852 800 906 020 (Toll Free)
United States
+1 844 606 0804 (Toll Free)
United Kingdom
+44 808 196 4551 (Toll Free)
Canada
+1 888 605 7930 (Toll Free)
Australia
+61 1300 986 386 (Toll Free)
EdgeOne hotline
+852 300 80699
More local hotlines coming soon