Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
D
DG_FAF
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
DG_FAF
Commits
ba9261eb
Commit
ba9261eb
authored
Feb 21, 2023
by
李维
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
调整一些逻辑
合并按钮在一个位置 多次点击音频停止上一次播放 调整正确错误图标大小和位置 分数可以配置不显示 页面销毁前播放音频
parent
785ff202
Changes
3
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
59 additions
and
16 deletions
+59
-16
DG_FAF.ts
assets/DG_FAF/scene/DG_FAF.ts
+46
-15
defaultData_DG_FAF.ts
assets/DG_FAF/script/defaultData_DG_FAF.ts
+1
-1
util_DG_FAF.ts
assets/DG_FAF/script/util_DG_FAF.ts
+12
-0
No files found.
assets/DG_FAF/scene/DG_FAF.ts
View file @
ba9261eb
import
{
import
{
playAudioByUrl
,
playAudioByUrl
,
loadImageByUrl
,
loadImageByUrl
,
asyncLoadRemote
,
getSprNode
,
getSprNode
,
}
from
"
../script/util_DG_FAF
"
;
}
from
"
../script/util_DG_FAF
"
;
import
{
MyCocosSceneComponent
}
from
"
../script/MyCocosSceneComponent_DG_FAF
"
;
import
{
MyCocosSceneComponent
}
from
"
../script/MyCocosSceneComponent_DG_FAF
"
;
...
@@ -197,9 +198,8 @@ export default class SceneComponent extends MyCocosSceneComponent {
...
@@ -197,9 +198,8 @@ export default class SceneComponent extends MyCocosSceneComponent {
// 配置提交按钮
// 配置提交按钮
this
.
setSubmitBtn
(
this
.
data
.
hotZoneItemArr
[
this
.
data
.
submitHotZoneIndex
]);
this
.
setSubmitBtn
(
this
.
data
.
hotZoneItemArr
[
this
.
data
.
submitHotZoneIndex
]);
this
.
setSubmitDisableBtn
(
this
.
data
.
hotZoneItemArr
[
this
.
data
.
submitHotZoneIndex
]);
this
.
setSubmitDisableBtn
(
this
.
data
.
hotZoneItemArr
[
this
.
data
.
submitHotZoneIndex
]);
// 配置重新开始按钮
// 配置重新开始按钮
this
.
setReplayBtn
(
this
.
data
.
hotZoneItemArr
[
this
.
data
.
replay
HotZoneIndex
]);
this
.
setReplayBtn
(
this
.
data
.
hotZoneItemArr
[
this
.
data
.
submit
HotZoneIndex
]);
// 检查是否可以提交
// 检查是否可以提交
this
.
checkCanSubmit
();
this
.
checkCanSubmit
();
...
@@ -227,6 +227,9 @@ export default class SceneComponent extends MyCocosSceneComponent {
...
@@ -227,6 +227,9 @@ export default class SceneComponent extends MyCocosSceneComponent {
// 计算每个分数显示区的数据
// 计算每个分数显示区的数据
this
.
subScorePanels
=
[];
this
.
subScorePanels
=
[];
this
.
data
.
scoreConfigArr
.
forEach
(
scoreConfig
=>
{
this
.
data
.
scoreConfigArr
.
forEach
(
scoreConfig
=>
{
if
(
isNaN
(
Number
(
scoreConfig
.
linkHotZoneIndex
)))
{
return
}
const
config
=
this
.
setScorePanel
(
this
.
data
.
hotZoneItemArr
[
scoreConfig
.
linkHotZoneIndex
],
15
);
const
config
=
this
.
setScorePanel
(
this
.
data
.
hotZoneItemArr
[
scoreConfig
.
linkHotZoneIndex
],
15
);
config
.
score
=
0
;
config
.
score
=
0
;
config
.
totalScore
=
0
;
config
.
totalScore
=
0
;
...
@@ -557,15 +560,22 @@ export default class SceneComponent extends MyCocosSceneComponent {
...
@@ -557,15 +560,22 @@ export default class SceneComponent extends MyCocosSceneComponent {
}
}
// 设置音频热区
// 设置音频热区
// 全局只能有一个音频播放 - 保存音乐id 用于停止
currentAudioPlay
=
null
;
setOneAudioBtn
(
contentData
,
hotZoneItemData
)
{
setOneAudioBtn
(
contentData
,
hotZoneItemData
)
{
const
{
sprNode
}
=
this
.
newSprNodeByResName
(
hotZoneItemData
,
"
icon_play_audio
"
);
const
{
sprNode
}
=
this
.
newSprNodeByResName
(
hotZoneItemData
,
"
icon_play_audio
"
);
sprNode
.
on
(
"
click
"
,
()
=>
{
sprNode
.
on
(
"
click
"
,
()
=>
{
if
(
this
.
submitted
)
{
if
(
this
.
submitted
)
{
return
;
return
;
}
}
playAudioByUrl
(
contentData
.
audio_url
,
()
=>
{
let
audioClip
=
asyncLoadRemote
(
contentData
.
audio_url
);
// 需要判断音频是否存在
})
if
(
audioClip
)
{
this
.
currentAudioPlay
=
cc
.
audioEngine
.
play
(
audioClip
,
false
,
0.8
);
cc
.
audioEngine
.
setFinishCallback
(
this
.
currentAudioPlay
,
()
=>
{
this
.
currentAudioPlay
=
null
;
});
}
})
})
};
};
...
@@ -641,8 +651,8 @@ export default class SceneComponent extends MyCocosSceneComponent {
...
@@ -641,8 +651,8 @@ export default class SceneComponent extends MyCocosSceneComponent {
sprNode
.
height
=
picNode
.
height
;
sprNode
.
height
=
picNode
.
height
;
}
}
// 在素材节点上添加按钮
sprNode
.
addComponent
(
cc
.
Button
);
sprNode
.
addComponent
(
cc
.
Button
);
picNode
.
addComponent
(
cc
.
Button
);
return
{
sprNode
,
picNode
};
return
{
sprNode
,
picNode
};
}
}
...
@@ -680,18 +690,19 @@ export default class SceneComponent extends MyCocosSceneComponent {
...
@@ -680,18 +690,19 @@ export default class SceneComponent extends MyCocosSceneComponent {
}
}
// 颜色色块
// 颜色色块
newMaskRectNode
(
data
)
{
newMaskRectNode
(
data
,
maskColor
=
"
#FFFF0066
"
)
{
const
highlightColor
=
"
#FFFF0066
"
;
const
rate
=
(
this
.
hotZoneBg
.
scale
*
this
.
hotZoneBg
.
width
)
/
this
.
data
.
bgItem
.
rect
.
width
;
const
rate
=
(
this
.
hotZoneBg
.
scale
*
this
.
hotZoneBg
.
width
)
/
this
.
data
.
bgItem
.
rect
.
width
;
const
rectNode
=
new
cc
.
Node
();
const
rectNode
=
new
cc
.
Node
();
rectNode
.
name
=
'
_mask_color_
'
;
rectNode
.
name
=
'
_mask_color_
'
;
// 调整颜色图层 - 置于最下层
rectNode
.
zIndex
=
-
1
;
this
.
hotZoneBg
.
addChild
(
rectNode
);
this
.
hotZoneBg
.
addChild
(
rectNode
);
// 红色矩形
// 红色矩形
const
ctx
=
rectNode
.
addComponent
(
cc
.
Graphics
);
const
ctx
=
rectNode
.
addComponent
(
cc
.
Graphics
);
ctx
.
lineWidth
=
4
;
ctx
.
lineWidth
=
4
;
const
color
=
new
cc
.
Color
();
const
color
=
new
cc
.
Color
();
cc
.
Color
.
fromHEX
(
color
,
highlight
Color
);
cc
.
Color
.
fromHEX
(
color
,
mask
Color
);
ctx
.
fillColor
=
color
;
ctx
.
fillColor
=
color
;
// 设置位置 大小 基准坐标
// 设置位置 大小 基准坐标
...
@@ -727,9 +738,13 @@ export default class SceneComponent extends MyCocosSceneComponent {
...
@@ -727,9 +738,13 @@ export default class SceneComponent extends MyCocosSceneComponent {
results
.
forEach
(
result
=>
{
results
.
forEach
(
result
=>
{
const
errIcon
=
getSprNode
(
"
icon_answer_wrong
"
);
const
errIcon
=
getSprNode
(
"
icon_answer_wrong
"
);
const
rightIcon
=
getSprNode
(
"
icon_answer_right
"
);
const
rightIcon
=
getSprNode
(
"
icon_answer_right
"
);
// 图标太大 缩小一半
errIcon
.
scale
=
rightIcon
.
scale
=
0.5
;
// 显示在热区的右下角
errIcon
.
x
=
rightIcon
.
x
=
result
.
rect
.
width
;
if
(
result
.
score
>=
0
)
{
if
(
result
.
score
>=
0
)
{
// 回答正确
// 回答正确
result
.
rect
.
addChild
(
rightIcon
)
result
.
rect
.
addChild
(
rightIcon
)
;
// 找到对应的组 计算该组得分
// 找到对应的组 计算该组得分
scoreCconfigArr
.
forEach
(
item
=>
{
scoreCconfigArr
.
forEach
(
item
=>
{
if
(
item
.
linkHotZoneIndexArr
.
indexOf
(
result
.
configIndex
)
!=
-
1
)
{
if
(
item
.
linkHotZoneIndexArr
.
indexOf
(
result
.
configIndex
)
!=
-
1
)
{
...
@@ -742,14 +757,20 @@ export default class SceneComponent extends MyCocosSceneComponent {
...
@@ -742,14 +757,20 @@ export default class SceneComponent extends MyCocosSceneComponent {
});
});
}
}
})
})
console
.
log
(
"
答案校验完毕
"
,
scoreCconfigArr
)
console
.
log
(
scoreCconfigArr
);
let
totalScore
=
0
;
let
totalScore
=
0
;
scoreCconfigArr
.
forEach
((
score
,
index
)
=>
{
scoreCconfigArr
.
forEach
((
score
,
index
)
=>
{
// 累加各个分数区域
totalScore
+=
score
.
score
;
totalScore
+=
score
.
score
;
// 如果配置了分数显示区域 - 显示分数
if
(
this
.
subScorePanels
[
index
])
{
this
.
subScorePanels
[
index
].
setScore
(
score
.
score
);
this
.
subScorePanels
[
index
].
setScore
(
score
.
score
);
}
})
})
// 如果配置了分数显示区域 - 显示分数
if
(
this
.
totalScorePanel
)
{
this
.
totalScorePanel
.
setScore
(
totalScore
);
this
.
totalScorePanel
.
setScore
(
totalScore
);
}
// 标记已经提交 禁止页面事件
// 标记已经提交 禁止页面事件
this
.
submitted
=
true
;
this
.
submitted
=
true
;
...
@@ -778,6 +799,12 @@ export default class SceneComponent extends MyCocosSceneComponent {
...
@@ -778,6 +799,12 @@ export default class SceneComponent extends MyCocosSceneComponent {
this
.
subScorePanels
=
[];
this
.
subScorePanels
=
[];
this
.
totalScorePanel
=
null
;
this
.
totalScorePanel
=
null
;
// 停止当前正在播放的音乐
if
(
this
.
currentAudioPlay
)
{
cc
.
audioEngine
.
stop
(
this
.
currentAudioPlay
);
}
this
.
currentAudioPlay
=
null
;
this
.
hotZoneBg
.
children
.
forEach
(
child
=>
{
this
.
hotZoneBg
.
children
.
forEach
(
child
=>
{
child
.
destroy
();
child
.
destroy
();
})
})
...
@@ -811,5 +838,9 @@ export default class SceneComponent extends MyCocosSceneComponent {
...
@@ -811,5 +838,9 @@ export default class SceneComponent extends MyCocosSceneComponent {
}
}
})
})
}
}
onDestroy
()
{
cc
.
audioEngine
.
stop
(
this
.
currentAudioPlay
);
}
// update (dt) {},
// update (dt) {},
}
}
assets/DG_FAF/script/defaultData_DG_FAF.ts
View file @
ba9261eb
This diff is collapsed.
Click to expand it.
assets/DG_FAF/script/util_DG_FAF.ts
View file @
ba9261eb
...
@@ -113,6 +113,18 @@ export function playAudioByUrl(audio_url, cb=null) {
...
@@ -113,6 +113,18 @@ export function playAudioByUrl(audio_url, cb=null) {
}
}
}
}
export
function
asyncLoadRemote
(
asstes_url
)
{
return
new
Promise
((
resovle
,
reject
)
=>
{
cc
.
assetManager
.
loadRemote
(
asstes_url
,
(
err
,
content
)
=>
{
if
(
err
)
{
resovle
(
err
)
}
else
{
resovle
(
content
)
}
});
})
}
export
function
loadImageByUrl
(
image_url
,
cb
=
null
)
{
export
function
loadImageByUrl
(
image_url
,
cb
=
null
)
{
if
(
image_url
)
{
if
(
image_url
)
{
cc
.
assetManager
.
loadRemote
(
image_url
,
(
err
,
texture
)
=>
{
cc
.
assetManager
.
loadRemote
(
image_url
,
(
err
,
texture
)
=>
{
...
...
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