tencent cloud

Accelerometer
마지막 업데이트 시간:2025-02-24 17:10:36
Accelerometer
마지막 업데이트 시간: 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.

문제 해결에 도움이 되었나요?
더 자세한 내용은 문의하기 또는 티켓 제출 을 통해 문의할 수 있습니다.
아니오

피드백