Commit 5f99a3b4 authored by Vũ Gia Vương's avatar Vũ Gia Vương

add debug ios

parent a9807606
This diff is collapsed.
...@@ -14,9 +14,11 @@ export default class HuController extends cc.Component { ...@@ -14,9 +14,11 @@ export default class HuController extends cc.Component {
private _count = 0; private _count = 0;
private _isShake = false; private _isShake = false;
private _track: TrackEntry = null; private _track: TrackEntry = null;
private _debug: cc.Label = null;
protected onLoad(): void { protected onLoad(): void {
this._spine = this.node.getComponent(sp.Skeleton); this._spine = this.node.getComponent(sp.Skeleton);
this._debug = this.node.getComponentInChildren(cc.Label);
this.node.on(cc.Node.EventType.TOUCH_START, this.onTouchStart, this); this.node.on(cc.Node.EventType.TOUCH_START, this.onTouchStart, this);
this.node.on(cc.Node.EventType.TOUCH_END, this.onTouchEnd, this) this.node.on(cc.Node.EventType.TOUCH_END, this.onTouchEnd, this)
...@@ -28,11 +30,53 @@ export default class HuController extends cc.Component { ...@@ -28,11 +30,53 @@ export default class HuController extends cc.Component {
this.initBottle(); this.initBottle();
}); });
if (cc.sys.os === cc.sys.OS_IOS) {
this.setDeviceMotionIOS();
}
else {
this.scheduleOnce(this.setDeviceMotion, 2); this.scheduleOnce(this.setDeviceMotion, 2);
}
this.initBottle(); this.initBottle();
} }
private setDeviceMotionIOS() {
const debug = (text: string) => {
this._debug.string = text;
}
debug('setDeviceMotionIOS');
if (window.DeviceMotionEvent) {
// Yêu cầu quyền truy cập trên iOS (từ iOS 13+)
if (typeof (DeviceMotionEvent as any).requestPermission === 'function') {
debug('requestPermission');
(DeviceMotionEvent as any).requestPermission()
.then(permissionState => {
debug('requestPermission: ' + permissionState);
if (permissionState === 'granted') {
debug('granted setDeviceMotion');
this.setDeviceMotion();
} else {
debug('Không được cấp quyền sử dụng DeviceMotion');
console.log('Không được cấp quyền sử dụng DeviceMotion');
}
})
.catch(e => {
console.error(e);
debug('Không được cấp quyền sử dụng DeviceMotion');
});
} else {
debug('Không hỗ trợ requestPermission');
this.setDeviceMotion();
}
} else {
debug('Trình duyệt không hỗ trợ DeviceMotion API');
console.log('Trình duyệt không hỗ trợ DeviceMotion API');
}
}
private initBottle() { private initBottle() {
this._spine.setAnimation(1, "Rotate", false); this._spine.setAnimation(1, "Rotate", false);
this._spine.timeScale = this._pointStart ? 0 : 0.5; this._spine.timeScale = this._pointStart ? 0 : 0.5;
...@@ -50,6 +94,7 @@ export default class HuController extends cc.Component { ...@@ -50,6 +94,7 @@ export default class HuController extends cc.Component {
private onTouchEnd(): void { private onTouchEnd(): void {
this.scheduleOnce(() => { this.scheduleOnce(() => {
this._spine.timeScale = 0; this._spine.timeScale = 0;
console.log('this._track.trackTime', this._track.trackTime)
if (this._track.trackTime < 0) { if (this._track.trackTime < 0) {
this._track.trackTime = this._track.animationEnd - 1e-9; this._track.trackTime = this._track.animationEnd - 1e-9;
} }
......
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