Commit ba9261eb authored by 李维's avatar 李维

调整一些逻辑

合并按钮在一个位置
多次点击音频停止上一次播放
调整正确错误图标大小和位置
分数可以配置不显示
页面销毁前播放音频
parent 785ff202
import {
playAudioByUrl,
loadImageByUrl,
asyncLoadRemote,
getSprNode,
} from "../script/util_DG_FAF";
import { MyCocosSceneComponent } from "../script/MyCocosSceneComponent_DG_FAF";
......@@ -197,9 +198,8 @@ export default class SceneComponent extends MyCocosSceneComponent {
// 配置提交按钮
this.setSubmitBtn(this.data.hotZoneItemArr[this.data.submitHotZoneIndex]);
this.setSubmitDisableBtn(this.data.hotZoneItemArr[this.data.submitHotZoneIndex]);
// 配置重新开始按钮
this.setReplayBtn(this.data.hotZoneItemArr[this.data.replayHotZoneIndex]);
this.setReplayBtn(this.data.hotZoneItemArr[this.data.submitHotZoneIndex]);
// 检查是否可以提交
this.checkCanSubmit();
......@@ -227,6 +227,9 @@ export default class SceneComponent extends MyCocosSceneComponent {
// 计算每个分数显示区的数据
this.subScorePanels = [];
this.data.scoreConfigArr.forEach(scoreConfig => {
if(isNaN(Number(scoreConfig.linkHotZoneIndex))) {
return
}
const config = this.setScorePanel(this.data.hotZoneItemArr[scoreConfig.linkHotZoneIndex], 15);
config.score = 0;
config.totalScore = 0;
......@@ -301,7 +304,7 @@ export default class SceneComponent extends MyCocosSceneComponent {
this.btnSubmitDisable = sprNode;
this.btnSubmitDisable.active = true;
this.btnSubmitDisable.on("click", ()=>{
})
}
......@@ -557,15 +560,22 @@ export default class SceneComponent extends MyCocosSceneComponent {
}
// 设置音频热区
// 全局只能有一个音频播放 - 保存音乐id 用于停止
currentAudioPlay = null;
setOneAudioBtn(contentData, hotZoneItemData) {
const {sprNode} = this.newSprNodeByResName(hotZoneItemData, "icon_play_audio");
sprNode.on("click", () => {
if(this.submitted) {
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 {
sprNode.height = picNode.height;
}
// 在素材节点上添加按钮
sprNode.addComponent(cc.Button);
picNode.addComponent(cc.Button);
return {sprNode, picNode};
}
......@@ -680,18 +690,19 @@ export default class SceneComponent extends MyCocosSceneComponent {
}
// 颜色色块
newMaskRectNode(data) {
const highlightColor = "#FFFF0066";
newMaskRectNode(data, maskColor = "#FFFF0066") {
const rate = (this.hotZoneBg.scale * this.hotZoneBg.width) / this.data.bgItem.rect.width;
const rectNode = new cc.Node();
rectNode.name = '_mask_color_';
// 调整颜色图层 - 置于最下层
rectNode.zIndex = -1;
this.hotZoneBg.addChild(rectNode);
// 红色矩形
const ctx = rectNode.addComponent(cc.Graphics);
ctx.lineWidth = 4;
const color = new cc.Color();
cc.Color.fromHEX(color, highlightColor);
cc.Color.fromHEX(color, maskColor);
ctx.fillColor = color;
// 设置位置 大小 基准坐标
......@@ -727,9 +738,13 @@ export default class SceneComponent extends MyCocosSceneComponent {
results.forEach(result => {
const errIcon = getSprNode("icon_answer_wrong");
const rightIcon = getSprNode("icon_answer_right");
// 图标太大 缩小一半
errIcon.scale = rightIcon.scale = 0.5;
// 显示在热区的右下角
errIcon.x = rightIcon.x = result.rect.width;
if(result.score >= 0) {
// 回答正确
result.rect.addChild(rightIcon)
result.rect.addChild(rightIcon);
// 找到对应的组 计算该组得分
scoreCconfigArr.forEach(item=>{
if(item.linkHotZoneIndexArr.indexOf(result.configIndex) != -1) {
......@@ -742,14 +757,20 @@ export default class SceneComponent extends MyCocosSceneComponent {
});
}
})
console.log(scoreCconfigArr);
console.log("答案校验完毕", scoreCconfigArr)
let totalScore = 0;
scoreCconfigArr.forEach((score, index) => {
// 累加各个分数区域
totalScore += score.score;
this.subScorePanels[index].setScore(score.score);
// 如果配置了分数显示区域 - 显示分数
if(this.subScorePanels[index]) {
this.subScorePanels[index].setScore(score.score);
}
})
this.totalScorePanel.setScore(totalScore);
// 如果配置了分数显示区域 - 显示分数
if(this.totalScorePanel) {
this.totalScorePanel.setScore(totalScore);
}
// 标记已经提交 禁止页面事件
this.submitted = true;
......@@ -778,6 +799,12 @@ export default class SceneComponent extends MyCocosSceneComponent {
this.subScorePanels = [];
this.totalScorePanel = null;
// 停止当前正在播放的音乐
if(this.currentAudioPlay) {
cc.audioEngine.stop(this.currentAudioPlay);
}
this.currentAudioPlay = null;
this.hotZoneBg.children.forEach(child=>{
child.destroy();
})
......@@ -811,5 +838,9 @@ export default class SceneComponent extends MyCocosSceneComponent {
}
})
}
onDestroy() {
cc.audioEngine.stop(this.currentAudioPlay);
}
// update (dt) {},
}
This diff is collapsed.
......@@ -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) {
if (image_url) {
cc.assetManager.loadRemote(image_url, (err, texture) => {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment