Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cc_mz_007
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
cc_mz_007
Commits
d6b514d3
Commit
d6b514d3
authored
Feb 09, 2022
by
范雪寒
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
test
parent
29470d78
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
58 additions
and
32 deletions
+58
-32
cc_mz_007.js
assets/cc_mz_007/scene/cc_mz_007.js
+20
-4
util.js
assets/cc_mz_007/script/util.js
+38
-28
No files found.
assets/cc_mz_007/scene/cc_mz_007.js
View file @
d6b514d3
...
...
@@ -5,7 +5,7 @@
// Learn life-cycle callbacks:
// - https://docs.cocos.com/creator/manual/en/scripting/life-cycle-callbacks.html
import
{
playAudioByUrl
,
setSprNodeMaxLen
,
btnClickAnima
}
from
"
../script/util
"
;
import
{
playAudioByUrl
,
setSprNodeMaxLen
,
btnClickAnima
,
asyncDelay
}
from
"
../script/util
"
;
cc
.
Class
({
extends
:
cc
.
Component
,
...
...
@@ -965,11 +965,22 @@ cc.Class({
return
;
}
cc
.
loader
.
load
(
image
,
(
error
,
texture
)
=>
{
cc
.
loader
.
load
({
url
:
atlas
,
type
:
'
txt
'
},
(
error
,
atlasJson
)
=>
{
cc
.
loader
.
load
({
url
:
ske
,
type
:
'
txt
'
},
(
error
,
dragonBonesJson
)
=>
{
cc
.
loader
.
load
(
image
,
async
(
error
,
texture
)
=>
{
this
.
log
(
'
error:
'
+
error
);
await
asyncDelay
(
3
);
cc
.
loader
.
load
({
url
:
atlas
,
type
:
'
txt
'
},
async
(
error
,
atlasJson
)
=>
{
this
.
log
(
'
error:
'
+
error
);
await
asyncDelay
(
3
);
cc
.
loader
.
load
({
url
:
ske
,
type
:
'
txt
'
},
async
(
error
,
dragonBonesJson
)
=>
{
this
.
log
(
'
error:
'
+
error
);
await
asyncDelay
(
3
);
this
.
log
(
'
汪汪汪1
'
);
await
asyncDelay
(
3
);
const
atlas
=
new
dragonBones
.
DragonBonesAtlasAsset
();
atlas
.
atlasJson
=
atlasJson
;
atlas
.
texture
=
texture
;
...
...
@@ -984,13 +995,16 @@ cc.Class({
let
armatures
=
json
[
"
armature
"
];
// console.log('armatures: ', armatures);
let
armatureNames
=
[];
await
asyncDelay
(
3
);
this
.
log
(
'
汪汪汪2
'
);
for
(
let
i
=
0
;
i
<
armatures
.
length
;
i
++
)
{
armatureNames
.
push
(
armatures
[
i
].
name
);
}
await
asyncDelay
(
3
);
this
.
log
(
'
汪汪汪3
'
);
// console.log('armatureNames: ', armatureNames);
if
(
armatureNames
.
length
>
0
)
{
await
asyncDelay
(
3
);
this
.
log
(
'
汪汪汪4
'
);
let
defaultArmatureName
=
armatureNames
[
0
];
dragonDisplay
.
armatureName
=
defaultArmatureName
;
...
...
@@ -1007,12 +1021,14 @@ cc.Class({
dragonDisplay
.
playAnimation
(
'
normal
'
,
-
1
);
dragonDisplay
.
animaNames
=
animationNames
;
animaNode
.
y
-=
30
;
await
asyncDelay
(
3
);
this
.
log
(
'
汪汪汪5
'
);
if
(
animaNode
.
height
)
{
animaNode
.
scale
=
376
/
animaNode
.
height
;
}
}
await
asyncDelay
(
3
);
this
.
log
(
'
汪汪汪
'
);
});
});
...
...
assets/cc_mz_007/script/util.js
View file @
d6b514d3
...
...
@@ -71,64 +71,74 @@ export function setSprNodeMaxLen(sprNode, maxW, maxH) {
}
export
function
localPosTolocalPos
(
baseNode
,
targetNode
)
{
const
worldPos
=
targetNode
.
parent
.
convertToWorldSpaceAR
(
cc
.
v2
(
targetNode
.
x
,
targetNode
.
y
));
const
localPos
=
baseNode
.
parent
.
convertToNodeSpaceAR
(
cc
.
v2
(
worldPos
.
x
,
worldPos
.
y
));
return
localPos
;
const
worldPos
=
targetNode
.
parent
.
convertToWorldSpaceAR
(
cc
.
v2
(
targetNode
.
x
,
targetNode
.
y
));
const
localPos
=
baseNode
.
parent
.
convertToNodeSpaceAR
(
cc
.
v2
(
worldPos
.
x
,
worldPos
.
y
));
return
localPos
;
}
export
function
worldPosToLocalPos
(
worldPos
,
baseNode
)
{
const
localPos
=
baseNode
.
parent
.
convertToNodeSpaceAR
(
cc
.
v2
(
worldPos
.
x
,
worldPos
.
y
));
return
localPos
;
const
localPos
=
baseNode
.
parent
.
convertToNodeSpaceAR
(
cc
.
v2
(
worldPos
.
x
,
worldPos
.
y
));
return
localPos
;
}
export
function
getScaleRateBy2Node
(
baseNode
,
targetNode
,
maxFlag
=
true
)
{
const
worldRect1
=
targetNode
.
getBoundingBoxToWorld
();
const
worldRect2
=
baseNode
.
getBoundingBoxToWorld
();
const
sx
=
worldRect1
.
width
/
worldRect2
.
width
;
const
sy
=
worldRect1
.
height
/
worldRect2
.
height
;
if
(
maxFlag
)
{
return
Math
.
max
(
sx
,
sy
);
}
else
{
return
Math
.
min
(
sx
,
sy
);
}
const
worldRect1
=
targetNode
.
getBoundingBoxToWorld
();
const
worldRect2
=
baseNode
.
getBoundingBoxToWorld
();
const
sx
=
worldRect1
.
width
/
worldRect2
.
width
;
const
sy
=
worldRect1
.
height
/
worldRect2
.
height
;
if
(
maxFlag
)
{
return
Math
.
max
(
sx
,
sy
);
}
else
{
return
Math
.
min
(
sx
,
sy
);
}
}
export
function
getDistance
(
start
,
end
)
{
var
pos
=
cc
.
v2
(
start
.
x
-
end
.
x
,
start
.
y
-
end
.
y
);
var
dis
=
Math
.
sqrt
(
pos
.
x
*
pos
.
x
+
pos
.
y
*
pos
.
y
);
return
dis
;
export
function
getDistance
(
start
,
end
)
{
var
pos
=
cc
.
v2
(
start
.
x
-
end
.
x
,
start
.
y
-
end
.
y
);
var
dis
=
Math
.
sqrt
(
pos
.
x
*
pos
.
x
+
pos
.
y
*
pos
.
y
);
return
dis
;
}
export
function
playAudioByUrl
(
audio_url
,
cb
=
null
)
{
if
(
audio_url
)
{
cc
.
assetManager
.
loadRemote
(
audio_url
,
(
err
,
audioClip
)
=>
{
export
function
playAudioByUrl
(
audio_url
,
cb
=
null
)
{
if
(
audio_url
)
{
cc
.
assetManager
.
loadRemote
(
audio_url
,
(
err
,
audioClip
)
=>
{
const
audioId
=
cc
.
audioEngine
.
play
(
audioClip
,
false
,
0.8
);
if
(
cb
)
{
cc
.
audioEngine
.
setFinishCallback
(
audioId
,
()
=>
{
cb
();
});
}
});
}
});
}
}
export
function
asyncDelay
(
time
)
{
return
new
Promise
((
resolve
,
reject
)
=>
{
cc
.
tween
(
cc
.
find
(
'
Canvas
'
))
.
delay
(
time
)
.
call
(()
=>
{
resolve
();
})
.
start
();
});
}
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
.
on
(
cc
.
Node
.
EventType
.
TOUCH_START
,
()
=>
{
cc
.
tween
(
btn
)
.
to
(
time
/
2
,
{
scale
:
btn
.
scale
*
rate
})
.
to
(
time
/
2
,
{
scale
:
btn
.
scale
*
rate
})
.
start
()
})
btn
.
on
(
cc
.
Node
.
EventType
.
TOUCH_CANCEL
,
()
=>
{
cc
.
tween
(
btn
)
.
to
(
time
/
2
,
{
scale
:
btn
.
tmpScale
})
.
to
(
time
/
2
,
{
scale
:
btn
.
tmpScale
})
.
start
()
})
btn
.
on
(
cc
.
Node
.
EventType
.
TOUCH_END
,
()
=>
{
cc
.
tween
(
btn
)
.
to
(
time
/
2
,
{
scale
:
btn
.
tmpScale
})
.
to
(
time
/
2
,
{
scale
:
btn
.
tmpScale
})
.
start
()
})
}
\ No newline at end of file
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