Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
O
op_01
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
op_01
Commits
5fd800fc
Commit
5fd800fc
authored
Sep 25, 2021
by
范雪寒
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: 结束音频与热区读音冲突问题
parent
b0d27c7b
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
77 additions
and
68 deletions
+77
-68
op_01.js
play/assets/op_01/scene/op_01.js
+77
-68
No files found.
play/assets/op_01/scene/op_01.js
View file @
5fd800fc
import
{
onHomeworkFinish
,
playAudioByUrl
,
playDragonBoneAnimation
}
from
"
../script/util
"
;
import
{
asyncDelay
,
onHomeworkFinish
,
playDragonBoneAnimation
}
from
"
../script/util
"
;
import
{
defaultData
}
from
"
../script/defaultData
"
;
import
{
defaultData
}
from
"
../script/defaultData
"
;
cc
.
Class
({
cc
.
Class
({
...
@@ -140,49 +140,56 @@ cc.Class({
...
@@ -140,49 +140,56 @@ cc.Class({
},
},
initView
()
{
async
initView
()
{
this
.
coolCatSpeakStart
(()
=>
{
this
.
coolCatSpeakStart
();
});
const
canvas
=
cc
.
find
(
'
Canvas
'
);
const
bg
=
cc
.
find
(
'
Canvas/bg/ImgBg
'
);
const
bg
=
cc
.
find
(
'
Canvas/bg/ImgBg
'
);
this
.
loadSpriteByUrl
(
bg
,
this
.
data
.
bgItem
.
url
,
()
=>
{
await
this
.
asyncLoadSpriteByUrl
(
bg
,
this
.
data
.
bgItem
.
url
);
const
canvas
=
cc
.
find
(
'
Canvas
'
);
bg
.
scale
=
Math
.
min
((
canvas
.
width
/
bg
.
width
),
(
canvas
.
height
/
bg
.
height
));
bg
.
scale
=
Math
.
min
((
canvas
.
width
/
bg
.
width
),
(
canvas
.
height
/
bg
.
height
));
this
.
itemList
=
[];
this
.
itemList
=
[];
this
.
data
.
hotZoneItemArr
.
forEach
(
async
itemData
=>
{
this
.
data
.
hotZoneItemArr
.
forEach
(
async
itemData
=>
{
const
item
=
await
this
.
createItem
(
itemData
,
bg
);
const
item
=
await
this
.
createItem
(
itemData
,
bg
);
this
.
itemList
.
push
(
item
);
this
.
itemList
.
push
(
item
);
item
.
on
(
'
click
'
,
()
=>
{
});
item
.
clicked
=
true
;
},
if
(
this
.
itemList
.
every
(
tmpItem
=>
tmpItem
.
clicked
))
{
this
.
coolCatSpeakEnd
();
shakeItem
(
item
)
{
}
playAudioByUrl
(
itemData
.
audio_url
);
const
time
=
0.05
;
const
time
=
0.05
;
cc
.
tween
(
item
)
cc
.
tween
(
item
)
.
to
(
time
,
{
angle
:
10
})
.
to
(
time
,
{
angle
:
10
})
.
to
(
time
*
2
,
{
angle
:
-
10
})
.
to
(
time
*
2
,
{
angle
:
-
10
})
.
to
(
time
,
{
angle
:
0
})
.
to
(
time
,
{
angle
:
0
})
.
start
();
.
start
();
});
});
});
},
},
createItem
(
itemData
,
bg
)
{
async
createItem
(
itemData
,
bg
)
{
return
new
Promise
((
resolve
,
reject
)
=>
{
const
bgScale
=
bg
.
width
/
this
.
data
.
bgItem
.
rect
.
width
;
const
bgScale
=
bg
.
width
/
this
.
data
.
bgItem
.
rect
.
width
;
const
item
=
cc
.
instantiate
(
cc
.
find
(
'
item
'
));
const
item
=
cc
.
instantiate
(
cc
.
find
(
'
item
'
));
item
.
parent
=
bg
;
item
.
parent
=
bg
;
this
.
loadSpriteByUrl
(
item
,
itemData
.
pic_url
,
()
=>
{
item
.
on
(
'
click
'
,
async
()
=>
{
item
.
clicked
=
true
;
this
.
shakeItem
(
item
);
await
this
.
asyncPlayAudioByUrl
(
itemData
.
audio_url
);
if
(
this
.
itemList
.
every
(
tmpItem
=>
tmpItem
.
clicked
))
{
await
asyncDelay
(
0.3
);
await
this
.
coolCatSpeakEnd
();
onHomeworkFinish
();
}
});
await
this
.
asyncLoadSpriteByUrl
(
item
,
itemData
.
pic_url
);
item
.
scale
=
itemData
.
imgScale
*
bgScale
;
item
.
scale
=
itemData
.
imgScale
*
bgScale
;
item
.
x
=
itemData
.
rect
.
x
*
bgScale
-
bg
.
width
/
2
+
item
.
width
*
item
.
scaleX
/
2
;
item
.
x
=
itemData
.
rect
.
x
*
bgScale
-
bg
.
width
/
2
+
item
.
width
*
item
.
scaleX
/
2
;
item
.
y
=
bg
.
height
/
2
-
itemData
.
rect
.
y
*
bgScale
-
item
.
height
*
item
.
scaleY
/
2
;
item
.
y
=
bg
.
height
/
2
-
itemData
.
rect
.
y
*
bgScale
-
item
.
height
*
item
.
scaleY
/
2
;
resolve
(
item
);
});
return
item
;
});
},
},
initListener
()
{
initListener
()
{
...
@@ -190,26 +197,18 @@ cc.Class({
...
@@ -190,26 +197,18 @@ cc.Class({
},
},
coolCatSpeakStart
(
cb
)
{
async
coolCatSpeakStart
(
cb
)
{
const
cat
=
cc
.
find
(
'
Canvas/catFrame/cat
'
);
const
cat
=
cc
.
find
(
'
Canvas/catFrame/cat
'
);
playDragonBoneAnimation
(
cat
,
'
begin
'
,
-
1
);
playDragonBoneAnimation
(
cat
,
'
begin
'
,
-
1
);
this
.
playAudioByUrl
(
this
.
data
.
startAudio
,
()
=>
{
await
this
.
asyncPlayAudioByUrl
(
this
.
data
.
startAudio
);
playDragonBoneAnimation
(
cat
,
'
normal
'
,
-
1
);
playDragonBoneAnimation
(
cat
,
'
normal
'
,
-
1
);
if
(
cb
)
{
cb
();
}
});
},
},
coolCatSpeakEnd
(
cb
)
{
async
coolCatSpeakEnd
(
)
{
const
cat
=
cc
.
find
(
'
Canvas/catFrame/cat
'
);
const
cat
=
cc
.
find
(
'
Canvas/catFrame/cat
'
);
playDragonBoneAnimation
(
cat
,
'
finish
'
,
-
1
);
playDragonBoneAnimation
(
cat
,
'
finish
'
,
-
1
);
this
.
playAudioByUrl
(
this
.
data
.
endAudio
,
()
=>
{
await
this
.
asyncPlayAudioByUrl
(
this
.
data
.
endAudio
);
playDragonBoneAnimation
(
cat
,
'
normal
'
,
-
1
);
playDragonBoneAnimation
(
cat
,
'
normal
'
,
-
1
);
if
(
cb
)
{
cb
();
}
});
},
},
...
@@ -233,27 +232,37 @@ cc.Class({
...
@@ -233,27 +232,37 @@ cc.Class({
loadSpriteByUrl
(
node
,
url
,
cb
)
{
asyncLoadSpriteByUrl
(
node
,
url
)
{
return
new
Promise
((
resolve
,
reject
)
=>
{
cc
.
loader
.
load
({
url
},
(
err
,
img
)
=>
{
cc
.
loader
.
load
({
url
},
(
err
,
img
)
=>
{
const
spriteFrame
=
new
cc
.
SpriteFrame
(
img
)
const
spriteFrame
=
new
cc
.
SpriteFrame
(
img
)
const
spr
=
node
.
getComponent
(
cc
.
Sprite
);
const
spr
=
node
.
getComponent
(
cc
.
Sprite
);
spr
.
spriteFrame
=
spriteFrame
;
spr
.
spriteFrame
=
spriteFrame
;
if
(
cb
)
{
resolve
();
cb
();
});
}
});
});
},
},
playAudioByUrl
(
audio_url
,
cb
=
null
)
{
currentAudioId
:
null
,
if
(
audio_url
)
{
stopCurrentAudio
()
{
if
(
this
.
currentAudioId
!==
null
)
{
cc
.
audioEngine
.
stop
(
this
.
currentAudioId
);
this
.
currentAudioId
=
null
;
}
},
asyncPlayAudioByUrl
(
audio_url
)
{
if
(
!
audio_url
)
{
return
;
}
return
new
Promise
((
resolve
,
reject
)
=>
{
cc
.
assetManager
.
loadRemote
(
audio_url
,
(
err
,
audioClip
)
=>
{
cc
.
assetManager
.
loadRemote
(
audio_url
,
(
err
,
audioClip
)
=>
{
this
.
stopCurrentAudio
();
const
audioId
=
cc
.
audioEngine
.
play
(
audioClip
,
false
,
0.8
);
const
audioId
=
cc
.
audioEngine
.
play
(
audioClip
,
false
,
0.8
);
if
(
cb
)
{
cc
.
audioEngine
.
setFinishCallback
(
audioId
,
()
=>
{
cc
.
audioEngine
.
setFinishCallback
(
audioId
,
()
=>
{
cb
();
resolve
();
});
});
});
}
});
});
}
},
},
});
});
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