Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
M
middleLayer_for_NJ
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
middleLayer_for_NJ
Commits
ffa2fa93
Commit
ffa2fa93
authored
May 25, 2022
by
范雪寒
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat:
parent
6dd244b5
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
98 additions
and
81 deletions
+98
-81
util.ts
assets/middleLayer_for_NJ/script/util.ts
+98
-81
No files found.
assets/middleLayer_for_NJ/script/util.ts
View file @
ffa2fa93
...
@@ -71,64 +71,64 @@ export function setSprNodeMaxLen(sprNode, maxW, maxH) {
...
@@ -71,64 +71,64 @@ export function setSprNodeMaxLen(sprNode, maxW, maxH) {
}
}
export
function
localPosTolocalPos
(
baseNode
,
targetNode
)
{
export
function
localPosTolocalPos
(
baseNode
,
targetNode
)
{
const
worldPos
=
targetNode
.
parent
.
convertToWorldSpaceAR
(
cc
.
v2
(
targetNode
.
x
,
targetNode
.
y
));
const
worldPos
=
targetNode
.
parent
.
convertToWorldSpaceAR
(
cc
.
v2
(
targetNode
.
x
,
targetNode
.
y
));
const
localPos
=
baseNode
.
parent
.
convertToNodeSpaceAR
(
cc
.
v2
(
worldPos
.
x
,
worldPos
.
y
));
const
localPos
=
baseNode
.
parent
.
convertToNodeSpaceAR
(
cc
.
v2
(
worldPos
.
x
,
worldPos
.
y
));
return
localPos
;
return
localPos
;
}
}
export
function
worldPosToLocalPos
(
worldPos
,
baseNode
)
{
export
function
worldPosToLocalPos
(
worldPos
,
baseNode
)
{
const
localPos
=
baseNode
.
parent
.
convertToNodeSpaceAR
(
cc
.
v2
(
worldPos
.
x
,
worldPos
.
y
));
const
localPos
=
baseNode
.
parent
.
convertToNodeSpaceAR
(
cc
.
v2
(
worldPos
.
x
,
worldPos
.
y
));
return
localPos
;
return
localPos
;
}
}
export
function
getScaleRateBy2Node
(
baseNode
,
targetNode
,
maxFlag
=
true
)
{
export
function
getScaleRateBy2Node
(
baseNode
,
targetNode
,
maxFlag
=
true
)
{
const
worldRect1
=
targetNode
.
getBoundingBoxToWorld
();
const
worldRect1
=
targetNode
.
getBoundingBoxToWorld
();
const
worldRect2
=
baseNode
.
getBoundingBoxToWorld
();
const
worldRect2
=
baseNode
.
getBoundingBoxToWorld
();
const
sx
=
worldRect1
.
width
/
worldRect2
.
width
;
const
sx
=
worldRect1
.
width
/
worldRect2
.
width
;
const
sy
=
worldRect1
.
height
/
worldRect2
.
height
;
const
sy
=
worldRect1
.
height
/
worldRect2
.
height
;
if
(
maxFlag
)
{
if
(
maxFlag
)
{
return
Math
.
max
(
sx
,
sy
);
return
Math
.
max
(
sx
,
sy
);
}
else
{
}
else
{
return
Math
.
min
(
sx
,
sy
);
return
Math
.
min
(
sx
,
sy
);
}
}
}
}
export
function
getDistance
(
start
,
end
)
{
export
function
getDistance
(
start
,
end
)
{
var
pos
=
cc
.
v2
(
start
.
x
-
end
.
x
,
start
.
y
-
end
.
y
);
var
pos
=
cc
.
v2
(
start
.
x
-
end
.
x
,
start
.
y
-
end
.
y
);
var
dis
=
Math
.
sqrt
(
pos
.
x
*
pos
.
x
+
pos
.
y
*
pos
.
y
);
var
dis
=
Math
.
sqrt
(
pos
.
x
*
pos
.
x
+
pos
.
y
*
pos
.
y
);
return
dis
;
return
dis
;
}
}
export
function
playAudioByUrl
(
audio_url
,
cb
=
null
)
{
export
function
playAudioByUrl
(
audio_url
,
cb
=
null
)
{
if
(
audio_url
)
{
if
(
audio_url
)
{
cc
.
assetManager
.
loadRemote
(
audio_url
,
(
err
,
audioClip
)
=>
{
cc
.
assetManager
.
loadRemote
(
audio_url
,
(
err
,
audioClip
)
=>
{
const
audioId
=
cc
.
audioEngine
.
play
(
audioClip
,
false
,
0.8
);
const
audioId
=
cc
.
audioEngine
.
play
(
audioClip
,
false
,
0.8
);
if
(
cb
)
{
if
(
cb
)
{
cc
.
audioEngine
.
setFinishCallback
(
audioId
,
()
=>
{
cc
.
audioEngine
.
setFinishCallback
(
audioId
,
()
=>
{
cb
();
cb
();
});
});
}
}
});
});
}
}
}
}
export
function
btnClickAnima
(
btn
,
time
=
0.15
,
rate
=
1.05
)
{
export
function
btnClickAnima
(
btn
,
time
=
0.15
,
rate
=
1.05
)
{
btn
.
tmpScale
=
btn
.
scale
;
btn
.
tmpScale
=
btn
.
scale
;
btn
.
on
(
cc
.
Node
.
EventType
.
TOUCH_START
,
()
=>
{
btn
.
on
(
cc
.
Node
.
EventType
.
TOUCH_START
,
()
=>
{
cc
.
tween
(
btn
)
cc
.
tween
(
btn
)
.
to
(
time
/
2
,
{
scale
:
btn
.
scale
*
rate
})
.
to
(
time
/
2
,
{
scale
:
btn
.
scale
*
rate
})
.
start
()
.
start
()
})
})
btn
.
on
(
cc
.
Node
.
EventType
.
TOUCH_CANCEL
,
()
=>
{
btn
.
on
(
cc
.
Node
.
EventType
.
TOUCH_CANCEL
,
()
=>
{
cc
.
tween
(
btn
)
cc
.
tween
(
btn
)
.
to
(
time
/
2
,
{
scale
:
btn
.
tmpScale
})
.
to
(
time
/
2
,
{
scale
:
btn
.
tmpScale
})
.
start
()
.
start
()
})
})
btn
.
on
(
cc
.
Node
.
EventType
.
TOUCH_END
,
()
=>
{
btn
.
on
(
cc
.
Node
.
EventType
.
TOUCH_END
,
()
=>
{
cc
.
tween
(
btn
)
cc
.
tween
(
btn
)
.
to
(
time
/
2
,
{
scale
:
btn
.
tmpScale
})
.
to
(
time
/
2
,
{
scale
:
btn
.
tmpScale
})
.
start
()
.
start
()
})
})
}
}
...
@@ -179,7 +179,7 @@ export async function asyncDelay(time) {
...
@@ -179,7 +179,7 @@ export async function asyncDelay(time) {
try
{
try
{
cc
.
tween
(
cc
.
find
(
'
Canvas
'
))
cc
.
tween
(
cc
.
find
(
'
Canvas
'
))
.
delay
(
time
)
.
delay
(
time
)
.
call
(()
=>
{
.
call
(()
=>
{
resolve
(
null
);
resolve
(
null
);
})
})
.
start
();
.
start
();
...
@@ -191,69 +191,69 @@ export async function asyncDelay(time) {
...
@@ -191,69 +191,69 @@ export async function asyncDelay(time) {
export
async
function
asyncLoadDragonBoneAnime
(
node
,
{
skeJsonData
:
{
url
:
skeJsonDataUrl
},
texJsonData
:
{
url
:
texJsonDataUrl
},
texPngData
:
{
url
:
texPngDataUrl
}
})
{
export
async
function
asyncLoadDragonBoneAnime
(
node
,
{
skeJsonData
:
{
url
:
skeJsonDataUrl
},
texJsonData
:
{
url
:
texJsonDataUrl
},
texPngData
:
{
url
:
texPngDataUrl
}
})
{
if
(
!
texPngDataUrl
||
!
texJsonDataUrl
||
!
texPngDataUrl
if
(
!
texPngDataUrl
||
!
texJsonDataUrl
||
!
texPngDataUrl
||
texPngDataUrl
==
''
||
texJsonDataUrl
==
''
||
texPngDataUrl
==
''
)
{
||
texPngDataUrl
==
''
||
texJsonDataUrl
==
''
||
texPngDataUrl
==
''
)
{
return
;
return
;
}
}
return
new
Promise
((
resolve
,
reject
)
=>
{
return
new
Promise
((
resolve
,
reject
)
=>
{
if
(
node
.
animaNode
)
{
if
(
node
.
animaNode
)
{
node
.
animaNode
.
removeFromParent
();
node
.
animaNode
.
removeFromParent
();
}
const
animaNode
=
new
cc
.
Node
();
animaNode
.
name
=
'
animaNode
'
;
animaNode
.
parent
=
node
;
animaNode
.
active
=
true
;
node
.
animaNode
=
animaNode
;
const
dragonDisplay
=
animaNode
.
addComponent
(
dragonBones
.
ArmatureDisplay
);
const
loadTexture
=
new
Promise
((
resolve
,
reject
)
=>
{
cc
.
assetManager
.
loadRemote
(
texPngDataUrl
,
(
error
,
texture
)
=>
{
if
(
error
)
{
reject
(
error
);
}
}
const
animaNode
=
new
cc
.
Node
();
resolve
(
texture
);
animaNode
.
name
=
'
animaNode
'
;
});
animaNode
.
parent
=
node
;
});
animaNode
.
active
=
true
;
node
.
animaNode
=
animaNode
;
const
dragonDisplay
=
animaNode
.
addComponent
(
dragonBones
.
ArmatureDisplay
);
const
loadTexture
=
new
Promise
((
resolve
,
reject
)
=>
{
cc
.
assetManager
.
loadRemote
(
texPngDataUrl
,
(
error
,
texture
)
=>
{
if
(
error
)
{
reject
(
error
);
}
resolve
(
texture
);
});
});
const
loadTexJsonData
=
new
Promise
((
resolve
,
reject
)
=>
{
const
loadTexJsonData
=
new
Promise
((
resolve
,
reject
)
=>
{
cc
.
assetManager
.
loadAny
({
url
:
texJsonDataUrl
},
(
error
,
atlasJson
)
=>
{
cc
.
assetManager
.
loadAny
({
url
:
texJsonDataUrl
},
(
error
,
atlasJson
)
=>
{
if
(
error
)
{
if
(
error
)
{
reject
(
error
);
reject
(
error
);
}
}
resolve
(
atlasJson
);
resolve
(
atlasJson
);
});
});
});
});
const
loadSkeJsonData
=
new
Promise
((
resolve
,
reject
)
=>
{
const
loadSkeJsonData
=
new
Promise
((
resolve
,
reject
)
=>
{
cc
.
assetManager
.
loadAny
({
url
:
skeJsonDataUrl
},
(
error
,
dragonBonesJson
)
=>
{
cc
.
assetManager
.
loadAny
({
url
:
skeJsonDataUrl
},
(
error
,
dragonBonesJson
)
=>
{
if
(
error
)
{
if
(
error
)
{
reject
(
error
);
reject
(
error
);
}
}
resolve
(
dragonBonesJson
);
resolve
(
dragonBonesJson
);
});
});
});
});
Promise
.
all
([
loadTexture
,
loadTexJsonData
,
loadSkeJsonData
]).
then
(([
texture
,
atlasJson
,
dragonBonesJson
])
=>
{
Promise
.
all
([
loadTexture
,
loadTexJsonData
,
loadSkeJsonData
]).
then
(([
texture
,
atlasJson
,
dragonBonesJson
])
=>
{
const
atlas
=
new
dragonBones
.
DragonBonesAtlasAsset
();
const
atlas
=
new
dragonBones
.
DragonBonesAtlasAsset
();
atlas
.
atlasJson
=
JSON
.
stringify
(
atlasJson
);
atlas
.
atlasJson
=
JSON
.
stringify
(
atlasJson
);
atlas
.
texture
=
texture
;
atlas
.
texture
=
texture
;
const
asset
=
new
dragonBones
.
DragonBonesAsset
();
const
asset
=
new
dragonBones
.
DragonBonesAsset
();
asset
.
dragonBonesJson
=
JSON
.
stringify
(
dragonBonesJson
);
asset
.
dragonBonesJson
=
JSON
.
stringify
(
dragonBonesJson
);
dragonDisplay
.
dragonAtlasAsset
=
atlas
;
dragonDisplay
.
dragonAtlasAsset
=
atlas
;
dragonDisplay
.
dragonAsset
=
asset
;
dragonDisplay
.
dragonAsset
=
asset
;
let
armatureNames
=
dragonBonesJson
.
armature
.
map
(
data
=>
data
.
name
);
let
armatureNames
=
dragonBonesJson
.
armature
.
map
(
data
=>
data
.
name
);
if
(
armatureNames
.
length
>
0
)
{
if
(
armatureNames
.
length
>
0
)
{
dragonDisplay
.
armatureName
=
armatureNames
[
0
];
dragonDisplay
.
armatureName
=
armatureNames
[
0
];
}
}
resolve
(
animaNode
);
resolve
(
animaNode
);
});
});
});
});
}
}
export
class
FireworkSettings
{
export
class
FireworkSettings
{
...
@@ -505,6 +505,23 @@ export function jumpToCourseWare(courseWareId: number) {
...
@@ -505,6 +505,23 @@ export function jumpToCourseWare(courseWareId: number) {
}
}
}
}
export
function
buttonOnceClick
(
button
:
cc
.
Node
,
callback
:
Function
,
scale
=
1.1
)
{
button
.
once
(
'
click
'
,
()
=>
{
if
(
button
[
'
cantClick
'
])
{
return
;
}
button
[
'
cantClick
'
]
=
true
;
cc
.
tween
(
button
)
.
to
(
0.1
,
{
scale
:
scale
})
.
to
(
0.1
,
{
scale
:
1.0
})
.
call
(()
=>
{
button
[
'
cantClick
'
]
=
false
;
callback
&&
callback
();
})
.
start
();
});
}
export
function
buttonOnClick
(
button
:
cc
.
Node
,
callback
:
Function
,
scale
=
1.1
)
{
export
function
buttonOnClick
(
button
:
cc
.
Node
,
callback
:
Function
,
scale
=
1.1
)
{
button
.
on
(
'
click
'
,
()
=>
{
button
.
on
(
'
click
'
,
()
=>
{
if
(
button
[
'
cantClick
'
])
{
if
(
button
[
'
cantClick
'
])
{
...
...
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