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
3811eacc
Commit
3811eacc
authored
Mar 31, 2025
by
Vũ Gia Vương
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix rotate
parent
c4ac75bf
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
49 additions
and
60 deletions
+49
-60
HuController.ts
assets/scripts/GamePlay/HuController.ts
+49
-60
No files found.
assets/scripts/GamePlay/HuController.ts
View file @
3811eacc
...
@@ -4,9 +4,8 @@ const { ccclass, property } = cc._decorator;
...
@@ -4,9 +4,8 @@ const { ccclass, property } = cc._decorator;
@
ccclass
@
ccclass
export
default
class
HuController
extends
cc
.
Component
{
export
default
class
HuController
extends
cc
.
Component
{
private
spine
:
sp
.
Skeleton
=
null
;
private
_
isRotate
:
boolean
=
false
;
private
_
spine
:
sp
.
Skeleton
=
null
;
private
_pointStart
:
cc
.
Vec2
=
null
;
private
_pointStart
:
cc
.
Vec2
=
null
;
private
_x
:
number
=
0
;
private
_x
:
number
=
0
;
private
_y
:
number
=
0
;
private
_y
:
number
=
0
;
...
@@ -15,17 +14,63 @@ export default class HuController extends cc.Component {
...
@@ -15,17 +14,63 @@ export default class HuController extends cc.Component {
private
_isShake
=
false
;
private
_isShake
=
false
;
protected
onLoad
():
void
{
protected
onLoad
():
void
{
this
.
spine
=
this
.
node
.
getComponent
(
sp
.
Skeleton
);
this
.
_
spine
=
this
.
node
.
getComponent
(
sp
.
Skeleton
);
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
)
this
.
node
.
on
(
cc
.
Node
.
EventType
.
TOUCH_MOVE
,
this
.
onTouchMove
,
this
)
this
.
node
.
on
(
cc
.
Node
.
EventType
.
TOUCH_MOVE
,
this
.
onTouchMove
,
this
)
this
.
spine
.
setCompleteListener
(()
=>
{
this
.
_
spine
.
setCompleteListener
(()
=>
{
console
.
log
(
'setCompleteListener'
,)
console
.
log
(
'setCompleteListener'
,)
this
.
setRotateAnim
();
this
.
setRotateAnim
();
});
});
this
.
scheduleOnce
(
this
.
setDeviceMotion
,
2
);
this
.
scheduleOnce
(
this
.
setDeviceMotion
,
2
);
this
.
initBottle
();
}
private
initBottle
()
{
this
.
setRotateAnim
();
let
state
=
this
.
_spine
.
getState
();
let
track
=
state
.
tracks
[
1
];
track
.
trackTime
=
3
/
4
;
this
.
_spine
.
timeScale
=
0
;
}
private
onTouchStart
(
event
:
cc
.
Event
.
EventTouch
):
void
{
// if (!this._pointStart) {
// this.setRotateAnim();
// }
this
.
_pointStart
=
event
.
getLocation
();
this
.
_spine
.
timeScale
=
0
;
}
private
onTouchEnd
():
void
{
this
.
scheduleOnce
(()
=>
this
.
_spine
.
timeScale
=
0
,
0.5
);
let
state
=
this
.
_spine
.
getState
();
let
track
=
state
.
tracks
[
1
];
if
(
track
.
trackTime
<
0
)
{
track
.
trackTime
=
0
;
}
}
private
onTouchMove
(
event
:
cc
.
Event
.
EventTouch
):
void
{
const
newPoint
=
event
.
getLocation
();
const
distance
=
newPoint
.
x
-
this
.
_pointStart
.
x
;
if
(
Math
.
abs
(
distance
)
<
5
)
{
this
.
_spine
.
timeScale
=
0
;
return
;
}
this
.
_pointStart
=
newPoint
;
this
.
_spine
.
timeScale
=
distance
>
0
?
-
1
:
1
;
}
private
setRotateAnim
():
void
{
this
.
_spine
.
setAnimation
(
1
,
"Rotate"
,
false
);
this
.
_spine
.
timeScale
=
this
.
_pointStart
?
0
:
0.5
;
}
}
private
setDeviceMotion
()
{
private
setDeviceMotion
()
{
...
@@ -80,60 +125,4 @@ export default class HuController extends cc.Component {
...
@@ -80,60 +125,4 @@ export default class HuController extends cc.Component {
private
randomY
():
number
{
private
randomY
():
number
{
return
Math
.
random
()
*
100
-
50
;
return
Math
.
random
()
*
100
-
50
;
}
}
private
onTouchStart
(
event
:
cc
.
Event
.
EventTouch
):
void
{
if
(
!
this
.
_pointStart
)
{
this
.
setRotateAnim
();
}
this
.
_pointStart
=
event
.
getLocation
();
this
.
spine
.
timeScale
=
0
;
}
private
onTouchEnd
():
void
{
this
.
scheduleOnce
(()
=>
this
.
spine
.
timeScale
=
0
,
0.5
);
let
state
=
this
.
spine
.
getState
();
// Lấy AnimationState
let
track
=
state
.
tracks
[
1
];
// Lấy track 0 (thay số 0 nếu cần track khác)
console
.
log
(
'this.spine.timeScale'
,
this
.
spine
.
timeScale
)
console
.
log
(
'track'
,
track
)
}
private
onTouchMove
(
event
:
cc
.
Event
.
EventTouch
):
void
{
const
newPoint
=
event
.
getLocation
();
const
distance
=
newPoint
.
x
-
this
.
_pointStart
.
x
;
if
(
Math
.
abs
(
distance
)
<
5
)
{
this
.
spine
.
timeScale
=
0
;
return
;
}
this
.
_pointStart
=
newPoint
;
this
.
spine
.
timeScale
=
distance
>
0
?
-
1
:
1
;
}
private
setRotateAnim
():
void
{
this
.
spine
.
setAnimation
(
1
,
"Rotate"
,
false
);
this
.
spine
.
timeScale
=
this
.
_pointStart
?
0
:
0.5
;
}
private
pauseAnim
():
void
{
this
.
spine
.
timeScale
=
0
;
}
private
unPauseAnim
():
void
{
this
.
spine
.
timeScale
=
0.5
;
}
private
toggleAnim
():
void
{
if
(
this
.
_isRotate
)
{
this
.
unPauseAnim
();
}
else
{
this
.
pauseAnim
();
}
this
.
_isRotate
=
!
this
.
_isRotate
;
}
private
setIdleAnim
():
void
{
this
.
spine
.
setAnimation
(
1
,
"Idle"
,
false
);
}
}
}
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