Commit 82bcc33b authored by Vũ Gia Vương's avatar Vũ Gia Vương

fix deviceMotionPermission when reload scene

parent 4f8ba74d
import { eventTarget, PLAY_ROLLING_SOUND } from "../Events";
import { Global } from "../Global";
const { ccclass, property } = cc._decorator;
......@@ -14,7 +15,7 @@ export default class DevicemotionController extends cc.Component {
private _isShake = false;
protected onLoad(): void {
if (cc.sys.os === cc.sys.OS_IOS) {
if (cc.sys.os === cc.sys.OS_IOS && !Global.deviceMotionPermission) {
this.node.on('click', this.setDeviceMotionIOS, this);
}
else {
......@@ -28,6 +29,7 @@ export default class DevicemotionController extends cc.Component {
(DeviceMotionEvent as any).requestPermission()
.then(permissionState => {
if (permissionState === 'granted') {
Global.deviceMotionPermission = true;
this.setDeviceMotion();
} else {
console.log('Không được cấp quyền sử dụng DeviceMotion');
......
export class Global {
public static deviceMotionPermission: boolean = false;
public static getRandomTimeSkew() {
return Math.random() * 0.05 + 0.03;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment