Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
D
dap-hu
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Vũ Gia Vương
dap-hu
Commits
5613eb34
Commit
5613eb34
authored
May 11, 2025
by
Vũ Gia Vương
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update vibrate ios
parent
0f3b7ef9
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
124 additions
and
63 deletions
+124
-63
home.fire
assets/Scenes/home.fire
+112
-36
DevicemotionController.ts
assets/scripts/GamePlay/DevicemotionController.ts
+12
-26
project.json
settings/project.json
+0
-1
No files found.
assets/Scenes/home.fire
View file @
5613eb34
...
...
@@ -81,10 +81,10 @@
"_active": true,
"_components": [
{
"__id__": 2
2
"__id__": 2
3
},
{
"__id__": 2
3
"__id__": 2
4
}
],
"_prefab": null,
...
...
@@ -339,19 +339,25 @@
"__id__": 8
},
{
"__id__": 1
1
"__id__": 1
0
},
{
"__id__": 1
8
"__id__": 1
7
}
],
"_active": true,
"_components": [
{
"__id__": 19
},
{
"__id__": 20
},
{
"__id__": 21
},
{
"__id__": 22
}
],
"_prefab": null,
...
...
@@ -365,8 +371,8 @@
},
"_contentSize": {
"__type__": "cc.Size",
"width": 0,
"height": 0
"width":
108
0,
"height":
192
0
},
"_anchorPoint": {
"__type__": "cc.Vec2",
...
...
@@ -414,9 +420,6 @@
"_components": [
{
"__id__": 9
},
{
"__id__": 10
}
],
"_prefab": null,
...
...
@@ -499,16 +502,6 @@
"_atlas": null,
"_id": "d6/v6E1GJKI6thYeNNadhw"
},
{
"__type__": "ba0b5Nq4fNP4KvnrykIXx3T",
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 8
},
"_enabled": true,
"_id": "20KHqiUvtDYr2ObUS7qj6F"
},
{
"__type__": "cc.Node",
"_name": "SelectButton",
...
...
@@ -518,13 +511,13 @@
},
"_children": [
{
"__id__": 1
2
"__id__": 1
1
}
],
"_active": true,
"_components": [
{
"__id__": 1
7
"__id__": 1
6
}
],
"_prefab": null,
...
...
@@ -580,20 +573,20 @@
"_name": "Background",
"_objFlags": 512,
"_parent": {
"__id__": 1
1
"__id__": 1
0
},
"_children": [
{
"__id__": 1
3
"__id__": 1
2
}
],
"_active": true,
"_components": [
{
"__id__": 1
5
"__id__": 1
4
},
{
"__id__": 1
6
"__id__": 1
5
}
],
"_prefab": null,
...
...
@@ -649,13 +642,13 @@
"_name": "Label",
"_objFlags": 512,
"_parent": {
"__id__": 1
2
"__id__": 1
1
},
"_children": [],
"_active": true,
"_components": [
{
"__id__": 1
4
"__id__": 1
3
}
],
"_prefab": null,
...
...
@@ -711,7 +704,7 @@
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 1
3
"__id__": 1
2
},
"_enabled": true,
"_materials": [
...
...
@@ -746,7 +739,7 @@
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 1
2
"__id__": 1
1
},
"_enabled": true,
"_materials": [
...
...
@@ -778,7 +771,7 @@
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 1
2
"__id__": 1
1
},
"_enabled": true,
"alignMode": 0,
...
...
@@ -805,7 +798,7 @@
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 1
1
"__id__": 1
0
},
"_enabled": true,
"_normalMaterial": null,
...
...
@@ -878,7 +871,7 @@
"__uuid__": "29158224-f8dd-4661-a796-1ffab537140e"
},
"_N$target": {
"__id__": 1
2
"__id__": 1
1
},
"_id": "f90tlUC7RA1YLuKG15c4Pu"
},
...
...
@@ -893,7 +886,7 @@
"_active": true,
"_components": [
{
"__id__": 1
9
"__id__": 1
8
}
],
"_prefab": null,
...
...
@@ -949,7 +942,7 @@
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 1
8
"__id__": 1
7
},
"_enabled": true,
"_clip": {
...
...
@@ -972,13 +965,13 @@
},
"_enabled": true,
"selectBtnNode": {
"__id__": 1
1
"__id__": 1
0
},
"backgroundMusic": {
"__uuid__": "a61f36bb-65e5-43e9-82b6-5a8d59050d31"
},
"rollingSound": {
"__id__": 1
9
"__id__": 1
8
},
"_id": "45maHBUxRJZZuwRoPaDXFL"
},
...
...
@@ -992,6 +985,89 @@
"_enabled": true,
"_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",
"_name": "",
...
...
assets/scripts/GamePlay/DevicemotionController.ts
View file @
5613eb34
...
...
@@ -4,58 +4,42 @@ const { ccclass, property } = cc._decorator;
@
ccclass
export
default
class
DevicemotionController
extends
cc
.
Component
{
@
property
(
cc
.
Node
)
private
jarNode
:
cc
.
Node
;
private
_x
:
number
=
0
;
private
_y
:
number
=
0
;
private
_z
:
number
=
0
;
private
_count
=
0
;
private
_isShake
=
false
;
private
_debug
:
cc
.
Label
=
null
;
protected
onLoad
():
void
{
this
.
_debug
=
this
.
node
.
getComponentInChildren
(
cc
.
Label
);
this
.
scheduleOnce
(
this
.
setDeviceMotion
,
2
);
// if (cc.sys.os === cc.sys.OS_IOS) {
// this.setDeviceMotionIOS();
// }
// else {
// this.scheduleOnce(this.setDeviceMotion, 2);
// }
if
(
cc
.
sys
.
os
===
cc
.
sys
.
OS_IOS
)
{
this
.
node
.
on
(
'click'
,
this
.
setDeviceMotionIOS
,
this
);
}
else
{
this
.
scheduleOnce
(
this
.
setDeviceMotion
,
1
);
}
}
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'
);
}
}
...
...
@@ -101,8 +85,8 @@ export default class DevicemotionController extends cc.Component {
private
shakeBottle
()
{
eventTarget
.
emit
(
PLAY_ROLLING_SOUND
);
cc
.
tween
(
this
.
n
ode
)
.
repeat
(
5
,
cc
.
tween
(
this
.
n
ode
)
cc
.
tween
(
this
.
jarN
ode
)
.
repeat
(
5
,
cc
.
tween
(
this
.
jarN
ode
)
.
call
(()
=>
this
.
vibratePhone
())
.
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 {
private
vibratePhone
()
{
if
(
"vibrate"
in
navigator
)
{
navigator
.
vibrate
(
200
);
}
else
{
console
.
log
(
"Trình duyệt không hỗ trợ vibrate"
);
}
}
...
...
settings/project.json
View file @
5613eb34
...
...
@@ -31,7 +31,6 @@
"Toggle"
,
"TiledMap"
,
"VideoPlayer"
,
"Widget"
,
"WebView"
,
"3D"
,
"3D Primitive"
,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment