From ec3798b09789c679159c3b1f33aa844124f60344 Mon Sep 17 00:00:00 2001 From: PP Date: Fri, 1 Jun 2018 16:09:09 +0800 Subject: [PATCH] exchange x y axis if view is rotated on DeviceMotionEvent (#2788) fix babel commit --- cocos2d/core/platform/CCInputExtension.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/cocos2d/core/platform/CCInputExtension.js b/cocos2d/core/platform/CCInputExtension.js index d71fa2234e..3bee4aaa70 100644 --- a/cocos2d/core/platform/CCInputExtension.js +++ b/cocos2d/core/platform/CCInputExtension.js @@ -146,6 +146,11 @@ inputManager.didAccelerate = function (eventData) { z = (eventData["alpha"] / 90) * 0.981; } + if (cc.view._isRotated) { + let tmp = x; + x = -y; + y = tmp; + } mAcceleration.x = x; mAcceleration.y = y; mAcceleration.z = z;