Commit 5613eb34 authored by Vũ Gia Vương's avatar Vũ Gia Vương

update vibrate ios

parent 0f3b7ef9
...@@ -81,10 +81,10 @@ ...@@ -81,10 +81,10 @@
"_active": true, "_active": true,
"_components": [ "_components": [
{ {
"__id__": 22 "__id__": 23
}, },
{ {
"__id__": 23 "__id__": 24
} }
], ],
"_prefab": null, "_prefab": null,
...@@ -339,19 +339,25 @@ ...@@ -339,19 +339,25 @@
"__id__": 8 "__id__": 8
}, },
{ {
"__id__": 11 "__id__": 10
}, },
{ {
"__id__": 18 "__id__": 17
} }
], ],
"_active": true, "_active": true,
"_components": [ "_components": [
{
"__id__": 19
},
{ {
"__id__": 20 "__id__": 20
}, },
{ {
"__id__": 21 "__id__": 21
},
{
"__id__": 22
} }
], ],
"_prefab": null, "_prefab": null,
...@@ -365,8 +371,8 @@ ...@@ -365,8 +371,8 @@
}, },
"_contentSize": { "_contentSize": {
"__type__": "cc.Size", "__type__": "cc.Size",
"width": 0, "width": 1080,
"height": 0 "height": 1920
}, },
"_anchorPoint": { "_anchorPoint": {
"__type__": "cc.Vec2", "__type__": "cc.Vec2",
...@@ -414,9 +420,6 @@ ...@@ -414,9 +420,6 @@
"_components": [ "_components": [
{ {
"__id__": 9 "__id__": 9
},
{
"__id__": 10
} }
], ],
"_prefab": null, "_prefab": null,
...@@ -499,16 +502,6 @@ ...@@ -499,16 +502,6 @@
"_atlas": null, "_atlas": null,
"_id": "d6/v6E1GJKI6thYeNNadhw" "_id": "d6/v6E1GJKI6thYeNNadhw"
}, },
{
"__type__": "ba0b5Nq4fNP4KvnrykIXx3T",
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 8
},
"_enabled": true,
"_id": "20KHqiUvtDYr2ObUS7qj6F"
},
{ {
"__type__": "cc.Node", "__type__": "cc.Node",
"_name": "SelectButton", "_name": "SelectButton",
...@@ -518,13 +511,13 @@ ...@@ -518,13 +511,13 @@
}, },
"_children": [ "_children": [
{ {
"__id__": 12 "__id__": 11
} }
], ],
"_active": true, "_active": true,
"_components": [ "_components": [
{ {
"__id__": 17 "__id__": 16
} }
], ],
"_prefab": null, "_prefab": null,
...@@ -580,20 +573,20 @@ ...@@ -580,20 +573,20 @@
"_name": "Background", "_name": "Background",
"_objFlags": 512, "_objFlags": 512,
"_parent": { "_parent": {
"__id__": 11 "__id__": 10
}, },
"_children": [ "_children": [
{ {
"__id__": 13 "__id__": 12
} }
], ],
"_active": true, "_active": true,
"_components": [ "_components": [
{ {
"__id__": 15 "__id__": 14
}, },
{ {
"__id__": 16 "__id__": 15
} }
], ],
"_prefab": null, "_prefab": null,
...@@ -649,13 +642,13 @@ ...@@ -649,13 +642,13 @@
"_name": "Label", "_name": "Label",
"_objFlags": 512, "_objFlags": 512,
"_parent": { "_parent": {
"__id__": 12 "__id__": 11
}, },
"_children": [], "_children": [],
"_active": true, "_active": true,
"_components": [ "_components": [
{ {
"__id__": 14 "__id__": 13
} }
], ],
"_prefab": null, "_prefab": null,
...@@ -711,7 +704,7 @@ ...@@ -711,7 +704,7 @@
"_name": "", "_name": "",
"_objFlags": 0, "_objFlags": 0,
"node": { "node": {
"__id__": 13 "__id__": 12
}, },
"_enabled": true, "_enabled": true,
"_materials": [ "_materials": [
...@@ -746,7 +739,7 @@ ...@@ -746,7 +739,7 @@
"_name": "", "_name": "",
"_objFlags": 0, "_objFlags": 0,
"node": { "node": {
"__id__": 12 "__id__": 11
}, },
"_enabled": true, "_enabled": true,
"_materials": [ "_materials": [
...@@ -778,7 +771,7 @@ ...@@ -778,7 +771,7 @@
"_name": "", "_name": "",
"_objFlags": 0, "_objFlags": 0,
"node": { "node": {
"__id__": 12 "__id__": 11
}, },
"_enabled": true, "_enabled": true,
"alignMode": 0, "alignMode": 0,
...@@ -805,7 +798,7 @@ ...@@ -805,7 +798,7 @@
"_name": "", "_name": "",
"_objFlags": 0, "_objFlags": 0,
"node": { "node": {
"__id__": 11 "__id__": 10
}, },
"_enabled": true, "_enabled": true,
"_normalMaterial": null, "_normalMaterial": null,
...@@ -878,7 +871,7 @@ ...@@ -878,7 +871,7 @@
"__uuid__": "29158224-f8dd-4661-a796-1ffab537140e" "__uuid__": "29158224-f8dd-4661-a796-1ffab537140e"
}, },
"_N$target": { "_N$target": {
"__id__": 12 "__id__": 11
}, },
"_id": "f90tlUC7RA1YLuKG15c4Pu" "_id": "f90tlUC7RA1YLuKG15c4Pu"
}, },
...@@ -893,7 +886,7 @@ ...@@ -893,7 +886,7 @@
"_active": true, "_active": true,
"_components": [ "_components": [
{ {
"__id__": 19 "__id__": 18
} }
], ],
"_prefab": null, "_prefab": null,
...@@ -949,7 +942,7 @@ ...@@ -949,7 +942,7 @@
"_name": "", "_name": "",
"_objFlags": 0, "_objFlags": 0,
"node": { "node": {
"__id__": 18 "__id__": 17
}, },
"_enabled": true, "_enabled": true,
"_clip": { "_clip": {
...@@ -972,13 +965,13 @@ ...@@ -972,13 +965,13 @@
}, },
"_enabled": true, "_enabled": true,
"selectBtnNode": { "selectBtnNode": {
"__id__": 11 "__id__": 10
}, },
"backgroundMusic": { "backgroundMusic": {
"__uuid__": "a61f36bb-65e5-43e9-82b6-5a8d59050d31" "__uuid__": "a61f36bb-65e5-43e9-82b6-5a8d59050d31"
}, },
"rollingSound": { "rollingSound": {
"__id__": 19 "__id__": 18
}, },
"_id": "45maHBUxRJZZuwRoPaDXFL" "_id": "45maHBUxRJZZuwRoPaDXFL"
}, },
...@@ -992,6 +985,89 @@ ...@@ -992,6 +985,89 @@
"_enabled": true, "_enabled": true,
"_id": "45SawY9WtNFoz5vuln85q5" "_id": "45SawY9WtNFoz5vuln85q5"
}, },
{
"__type__": "ba0b5Nq4fNP4KvnrykIXx3T",
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 7
},
"_enabled": true,
"jarNode": {
"__id__": 8
},
"_id": "14rGyH0qNNroHm2lv0WrGb"
},
{
"__type__": "cc.Button",
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 7
},
"_enabled": true,
"_normalMaterial": null,
"_grayMaterial": null,
"duration": 0.1,
"zoomScale": 1.2,
"clickEvents": [],
"_N$interactable": true,
"_N$enableAutoGrayEffect": false,
"_N$transition": 0,
"transition": 0,
"_N$normalColor": {
"__type__": "cc.Color",
"r": 255,
"g": 255,
"b": 255,
"a": 255
},
"_N$pressedColor": {
"__type__": "cc.Color",
"r": 211,
"g": 211,
"b": 211,
"a": 255
},
"pressedColor": {
"__type__": "cc.Color",
"r": 211,
"g": 211,
"b": 211,
"a": 255
},
"_N$hoverColor": {
"__type__": "cc.Color",
"r": 255,
"g": 255,
"b": 255,
"a": 255
},
"hoverColor": {
"__type__": "cc.Color",
"r": 255,
"g": 255,
"b": 255,
"a": 255
},
"_N$disabledColor": {
"__type__": "cc.Color",
"r": 124,
"g": 124,
"b": 124,
"a": 255
},
"_N$normalSprite": null,
"_N$pressedSprite": null,
"pressedSprite": null,
"_N$hoverSprite": null,
"hoverSprite": null,
"_N$disabledSprite": null,
"_N$target": {
"__id__": 7
},
"_id": "19IBuSoKtDc59GTmYO5QKQ"
},
{ {
"__type__": "cc.Canvas", "__type__": "cc.Canvas",
"_name": "", "_name": "",
......
...@@ -4,58 +4,42 @@ const { ccclass, property } = cc._decorator; ...@@ -4,58 +4,42 @@ const { ccclass, property } = cc._decorator;
@ccclass @ccclass
export default class DevicemotionController extends cc.Component { export default class DevicemotionController extends cc.Component {
@property(cc.Node)
private jarNode: cc.Node;
private _x: number = 0; private _x: number = 0;
private _y: number = 0; private _y: number = 0;
private _z: number = 0; private _z: number = 0;
private _count = 0; private _count = 0;
private _isShake = false; private _isShake = false;
private _debug: cc.Label = null;
protected onLoad(): void { protected onLoad(): void {
this._debug = this.node.getComponentInChildren(cc.Label); if (cc.sys.os === cc.sys.OS_IOS) {
this.node.on('click', this.setDeviceMotionIOS, this);
this.scheduleOnce(this.setDeviceMotion, 2); }
// if (cc.sys.os === cc.sys.OS_IOS) { else {
// this.setDeviceMotionIOS(); this.scheduleOnce(this.setDeviceMotion, 1);
// } }
// else {
// this.scheduleOnce(this.setDeviceMotion, 2);
// }
} }
private setDeviceMotionIOS() { private setDeviceMotionIOS() {
const debug = (text: string) => {
this._debug.string = text;
}
debug('setDeviceMotionIOS');
if (window.DeviceMotionEvent) { 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') { if (typeof (DeviceMotionEvent as any).requestPermission === 'function') {
debug('requestPermission');
(DeviceMotionEvent as any).requestPermission() (DeviceMotionEvent as any).requestPermission()
.then(permissionState => { .then(permissionState => {
debug('requestPermission: ' + permissionState);
if (permissionState === 'granted') { if (permissionState === 'granted') {
debug('granted setDeviceMotion');
this.setDeviceMotion(); this.setDeviceMotion();
} else { } 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'); console.log('Không được cấp quyền sử dụng DeviceMotion');
} }
}) })
.catch(e => { .catch(e => {
console.error(e); console.error(e);
debug('Không được cấp quyền sử dụng DeviceMotion');
}); });
} else { } else {
debug('Không hỗ trợ requestPermission');
this.setDeviceMotion(); this.setDeviceMotion();
} }
} else { } else {
debug('Trình duyệt không hỗ trợ DeviceMotion API');
console.log('Trình duyệt không hỗ trợ DeviceMotion API'); console.log('Trình duyệt không hỗ trợ DeviceMotion API');
} }
} }
...@@ -101,8 +85,8 @@ export default class DevicemotionController extends cc.Component { ...@@ -101,8 +85,8 @@ export default class DevicemotionController extends cc.Component {
private shakeBottle() { private shakeBottle() {
eventTarget.emit(PLAY_ROLLING_SOUND); eventTarget.emit(PLAY_ROLLING_SOUND);
cc.tween(this.node) cc.tween(this.jarNode)
.repeat(5, cc.tween(this.node) .repeat(5, cc.tween(this.jarNode)
.call(() => this.vibratePhone()) .call(() => this.vibratePhone())
.to(0.2, { position: cc.v3(40, this.randomY(), 0) }) .to(0.2, { position: cc.v3(40, this.randomY(), 0) })
.to(0.2, { position: cc.v3(-40, this.randomY(), 0) }) .to(0.2, { position: cc.v3(-40, this.randomY(), 0) })
...@@ -114,6 +98,8 @@ export default class DevicemotionController extends cc.Component { ...@@ -114,6 +98,8 @@ export default class DevicemotionController extends cc.Component {
private vibratePhone() { private vibratePhone() {
if ("vibrate" in navigator) { if ("vibrate" in navigator) {
navigator.vibrate(200); navigator.vibrate(200);
} else {
console.log("Trình duyệt không hỗ trợ vibrate");
} }
} }
......
...@@ -31,7 +31,6 @@ ...@@ -31,7 +31,6 @@
"Toggle", "Toggle",
"TiledMap", "TiledMap",
"VideoPlayer", "VideoPlayer",
"Widget",
"WebView", "WebView",
"3D", "3D",
"3D Primitive", "3D Primitive",
......
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