Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
N
NGT_02
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
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
template admin
NGT_02
Commits
181499e2
Commit
181499e2
authored
Feb 24, 2022
by
范雪寒
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: initUtils_NGT_02
parent
50583886
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
268 additions
and
239 deletions
+268
-239
_preDefine.js
assets/NGT_02/script/common/_preDefine.js
+1
-0
utils.js
assets/NGT_02/script/common/utils.js
+267
-239
No files found.
assets/NGT_02/script/common/_preDefine.js
View file @
181499e2
...
...
@@ -7,4 +7,5 @@ function initGlobal_NGT_02() {
initStorageMgr_NGT_02
();
initResMgr_NGT_02
();
initSndMgr_NGT_02
();
initUtils_NGT_02
();
}
\ No newline at end of file
assets/NGT_02/script/common/utils.js
View file @
181499e2
g
.
utils
=
{
function
initUtils_NGT_02
()
{
g
.
utils
=
{
// 范围随机
randFromTo
:
function
(
_min
,
_max
)
{
var
min
=
parseFloat
(
_min
);
var
max
=
parseFloat
(
_max
);
return
(
min
+
Math
.
random
()
*
(
max
-
min
)
);
return
min
+
Math
.
random
()
*
(
max
-
min
);
},
// 范围随机一个整数
// 例:1~3,返回的可能值为:1、2、3
...
...
@@ -15,7 +16,7 @@ g.utils = {
deepCopy
:
function
(
src
)
{
var
cpy
=
src
instanceof
Array
?
[]
:
{};
for
(
var
i
in
src
)
{
cpy
[
i
]
=
typeof
src
[
i
]
===
'
object
'
?
this
.
deepCopy
(
src
[
i
])
:
src
[
i
];
cpy
[
i
]
=
typeof
src
[
i
]
===
"
object
"
?
this
.
deepCopy
(
src
[
i
])
:
src
[
i
];
}
return
cpy
;
},
...
...
@@ -23,11 +24,14 @@ g.utils = {
//生成唯一标识
generateUUID
:
function
()
{
var
d
=
new
Date
().
getTime
();
var
uuid
=
'
xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx
'
.
replace
(
/
[
xy
]
/g
,
function
(
c
)
{
var
uuid
=
"
xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx
"
.
replace
(
/
[
xy
]
/g
,
function
(
c
)
{
var
r
=
(
d
+
Math
.
random
()
*
16
)
%
16
|
0
;
d
=
Math
.
floor
(
d
/
16
);
return
(
c
==
'
x
'
?
r
:
(
r
&
0x3
|
0x8
)).
toString
(
16
);
});
return
(
c
==
"
x
"
?
r
:
(
r
&
0x3
)
|
0x8
).
toString
(
16
);
}
);
return
uuid
;
},
...
...
@@ -36,68 +40,74 @@ g.utils = {
if
(
index
>
-
1
)
{
this
.
splice
(
index
,
1
);
}
}
}
export
function
getPosByAngle
(
angle
,
len
)
{
},
};
const
radian
=
angle
*
Math
.
PI
/
180
;
export
function
getPosByAngle
(
angle
,
len
)
{
const
radian
=
(
angle
*
Math
.
PI
)
/
180
;
const
x
=
Math
.
sin
(
radian
)
*
len
;
const
y
=
Math
.
cos
(
radian
)
*
len
;
return
{
x
,
y
};
}
}
export
function
getAngleByPos
(
px
,
py
,
mx
,
my
)
{
export
function
getAngleByPos
(
px
,
py
,
mx
,
my
)
{
const
x
=
Math
.
abs
(
px
-
mx
);
const
y
=
Math
.
abs
(
py
-
my
);
const
z
=
Math
.
sqrt
(
Math
.
pow
(
x
,
2
)
+
Math
.
pow
(
y
,
2
));
const
cos
=
y
/
z
;
const
radina
=
Math
.
acos
(
cos
);
// 用反三角函数求弧度
let
angle
=
Math
.
floor
(
180
/
(
Math
.
PI
/
radina
)
*
100
)
/
100
;
// 将弧度转换成角度
let
angle
=
Math
.
floor
((
180
/
(
Math
.
PI
/
radina
)
)
*
100
)
/
100
;
// 将弧度转换成角度
if
(
mx
>
px
&&
my
>
py
)
{
// 鼠标在第四象限
if
(
mx
>
px
&&
my
>
py
)
{
// 鼠标在第四象限
angle
=
180
-
angle
;
}
if
(
mx
===
px
&&
my
>
py
)
{
// 鼠标在y轴负方向上
if
(
mx
===
px
&&
my
>
py
)
{
// 鼠标在y轴负方向上
angle
=
180
;
}
if
(
mx
>
px
&&
my
===
py
)
{
// 鼠标在x轴正方向上
if
(
mx
>
px
&&
my
===
py
)
{
// 鼠标在x轴正方向上
angle
=
90
;
}
if
(
mx
<
px
&&
my
>
py
)
{
// 鼠标在第三象限
if
(
mx
<
px
&&
my
>
py
)
{
// 鼠标在第三象限
angle
=
180
+
angle
;
}
if
(
mx
<
px
&&
my
===
py
)
{
// 鼠标在x轴负方向
if
(
mx
<
px
&&
my
===
py
)
{
// 鼠标在x轴负方向
angle
=
270
;
}
if
(
mx
<
px
&&
my
<
py
)
{
// 鼠标在第二象限
if
(
mx
<
px
&&
my
<
py
)
{
// 鼠标在第二象限
angle
=
360
-
angle
;
}
// console.log('angle: ', angle);
return
angle
;
}
}
export
function
exchangeNodePos
(
baseNode
,
targetNode
)
{
return
baseNode
.
convertToNodeSpaceAR
(
targetNode
.
_parent
.
convertToWorldSpaceAR
(
cc
.
v2
(
targetNode
.
x
,
targetNode
.
y
)));
}
export
function
exchangeNodePos
(
baseNode
,
targetNode
)
{
return
baseNode
.
convertToNodeSpaceAR
(
targetNode
.
_parent
.
convertToWorldSpaceAR
(
cc
.
v2
(
targetNode
.
x
,
targetNode
.
y
)
)
);
}
export
function
RandomInt
(
a
,
b
=
0
)
{
export
function
RandomInt
(
a
,
b
=
0
)
{
let
max
=
Math
.
max
(
a
,
b
);
let
min
=
Math
.
min
(
a
,
b
);
return
Math
.
floor
(
Math
.
random
()
*
(
max
-
min
)
+
min
);
}
}
export
function
Between
(
a
,
b
,
c
)
{
export
function
Between
(
a
,
b
,
c
)
{
return
[
a
,
b
,
c
].
sort
((
a
,
b
)
=>
a
-
b
)[
1
];
}
}
export
function
randomSortByArr
(
arr
)
{
export
function
randomSortByArr
(
arr
)
{
const
newArr
=
[];
const
tmpArr
=
arr
.
concat
();
while
(
tmpArr
.
length
>
0
)
{
...
...
@@ -106,9 +116,9 @@ export function randomSortByArr(arr) {
tmpArr
.
splice
(
randomIndex
,
1
);
}
return
newArr
;
}
}
export
async
function
asyncTweenTo
(
node
,
duration
,
obj
,
ease
=
undefined
)
{
export
async
function
asyncTweenTo
(
node
,
duration
,
obj
,
ease
=
undefined
)
{
return
new
Promise
((
resolve
,
reject
)
=>
{
cc
.
tween
(
node
)
.
to
(
duration
,
obj
,
ease
)
...
...
@@ -117,9 +127,9 @@ export async function asyncTweenTo(node, duration, obj, ease = undefined) {
})
.
start
();
});
}
}
export
async
function
asyncTweenBy
(
node
,
duration
,
obj
,
ease
=
undefined
)
{
export
async
function
asyncTweenBy
(
node
,
duration
,
obj
,
ease
=
undefined
)
{
return
new
Promise
((
resolve
,
reject
)
=>
{
cc
.
tween
(
node
)
.
by
(
duration
,
obj
,
ease
)
...
...
@@ -128,28 +138,36 @@ export async function asyncTweenBy(node, duration, obj, ease = undefined) {
})
.
start
();
});
}
}
export
async
function
asyncPlayDragonBoneAnimation
(
node
,
animationName
,
time
=
1
,
onFrameEvent
)
{
export
async
function
asyncPlayDragonBoneAnimation
(
node
,
animationName
,
time
=
1
,
onFrameEvent
)
{
return
new
Promise
((
resolve
,
reject
)
=>
{
node
.
getComponent
(
dragonBones
.
ArmatureDisplay
)
node
.
getComponent
(
dragonBones
.
ArmatureDisplay
)
.
once
(
dragonBones
.
EventObject
.
COMPLETE
,
()
=>
{
resolve
();
});
node
.
getComponent
(
dragonBones
.
ArmatureDisplay
)
node
.
getComponent
(
dragonBones
.
ArmatureDisplay
)
.
on
(
dragonBones
.
EventObject
.
FRAME_EVENT
,
({
name
})
=>
{
if
(
onFrameEvent
&&
typeof
(
onFrameEvent
)
==
'
function
'
)
{
if
(
onFrameEvent
&&
typeof
onFrameEvent
==
"
function
"
)
{
onFrameEvent
(
name
);
}
});
node
.
getComponent
(
dragonBones
.
ArmatureDisplay
)
node
.
getComponent
(
dragonBones
.
ArmatureDisplay
)
.
playAnimation
(
animationName
,
time
);
});
}
}
export
async
function
asyncPlayEffectByUrl
(
url
,
loop
=
false
)
{
export
async
function
asyncPlayEffectByUrl
(
url
,
loop
=
false
)
{
return
new
Promise
((
resolve
,
reject
)
=>
{
cc
.
assetManager
.
loadRemote
(
url
,
(
err
,
clip
)
=>
{
console
.
log
(
clip
);
...
...
@@ -157,9 +175,9 @@ export async function asyncPlayEffectByUrl(url, loop = false) {
resolve
();
});
});
}
}
export
async
function
jelly
(
node
)
{
export
async
function
jelly
(
node
)
{
return
new
Promise
((
resolve
,
reject
)
=>
{
cc
.
tween
(
node
)
.
to
(
0.1
,
{
scaleX
:
0.9
,
scaleY
:
1.1
})
...
...
@@ -168,19 +186,25 @@ export async function jelly(node) {
.
call
(
resolve
)
.
start
();
});
}
}
export
async
function
asyncDelay
(
time
)
{
export
async
function
asyncDelay
(
time
)
{
return
new
Promise
((
resolve
,
reject
)
=>
{
setTimeout
(()
=>
{
resolve
();
},
time
*
1000
);
})
}
export
async
function
showFireworks
(
baseNode
,
nodeList
,
pos
=
cc
.
v2
(
0
,
0
),
side
=
cc
.
v2
(
0
,
100
),
range
=
50
,
number
=
100
)
{
new
Array
(
number
).
fill
(
'
'
).
forEach
(
async
(
_
,
i
)
=>
{
});
}
export
async
function
showFireworks
(
baseNode
,
nodeList
,
pos
=
cc
.
v2
(
0
,
0
),
side
=
cc
.
v2
(
0
,
100
),
range
=
50
,
number
=
100
)
{
new
Array
(
number
).
fill
(
"
"
).
forEach
(
async
(
_
,
i
)
=>
{
let
rabbonNode
=
new
cc
.
Node
();
rabbonNode
.
parent
=
baseNode
;
rabbonNode
.
x
=
pos
.
x
;
...
...
@@ -197,16 +221,19 @@ export async function showFireworks(baseNode, nodeList, pos = cc.v2(0, 0), side
const
rate
=
Math
.
random
();
const
angle
=
Math
.
PI
*
(
Math
.
random
()
*
2
-
1
);
await
asyncTweenBy
(
rabbonNode
,
0.3
,
{
await
asyncTweenBy
(
rabbonNode
,
0.3
,
{
x
:
side
.
x
*
rate
+
Math
.
cos
(
angle
)
*
range
*
rate
,
y
:
side
.
y
*
rate
+
Math
.
sin
(
angle
)
*
range
*
rate
},
{
easing
:
'
quadIn
'
});
y
:
side
.
y
*
rate
+
Math
.
sin
(
angle
)
*
range
*
rate
,
},
{
easing
:
"
quadIn
"
,
}
);
cc
.
tween
(
rabbonNode
)
.
by
(
8
,
{
y
:
-
2000
})
.
start
();
cc
.
tween
(
rabbonNode
).
by
(
8
,
{
y
:
-
2000
}).
start
();
rabbonFall
(
rabbonNode
);
...
...
@@ -230,11 +257,12 @@ export async function showFireworks(baseNode, nodeList, pos = cc.v2(0, 0), side
})
.
start
();
});
}
}
async
function
rabbonFall
(
node
)
{
async
function
rabbonFall
(
node
)
{
const
time
=
1
+
Math
.
random
();
const
offsetX
=
RandomInt
(
-
200
,
200
)
*
time
;
await
asyncTweenBy
(
node
,
time
,
{
x
:
offsetX
,
angle
:
offsetX
*
60
/
200
});
await
asyncTweenBy
(
node
,
time
,
{
x
:
offsetX
,
angle
:
(
offsetX
*
60
)
/
200
});
rabbonFall
(
node
);
}
}
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