From 4d229b237a3aa6c9ae1db59594c6df017d039186 Mon Sep 17 00:00:00 2001 From: PP Date: Fri, 15 Jun 2018 14:45:05 +0800 Subject: [PATCH] add _unregisterAccelerometerEvent (#2865) --- cocos2d/core/platform/CCInputExtension.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/cocos2d/core/platform/CCInputExtension.js b/cocos2d/core/platform/CCInputExtension.js index 9f4a1c76fc..f9f2590999 100644 --- a/cocos2d/core/platform/CCInputExtension.js +++ b/cocos2d/core/platform/CCInputExtension.js @@ -95,6 +95,14 @@ inputManager._registerAccelerometerEvent = function(){ w.addEventListener(_deviceEventType, _t.didAccelerate.bind(_t), false); }; +inputManager._unregisterAccelerometerEvent = function () { + let w = window, _t = this; + let _deviceEventType = (_t._accelDeviceEvent === w.DeviceMotionEvent) ? "devicemotion" : "deviceorientation"; + if (_didAccelerateFun) { + w.removeEventListener(_deviceEventType, _didAccelerateFun, false); + } +}; + inputManager.didAccelerate = function (eventData) { var _t = this, w = window; if (!_t._accelEnabled)