Commit ba9261eb authored by 李维's avatar 李维

调整一些逻辑

合并按钮在一个位置
多次点击音频停止上一次播放
调整正确错误图标大小和位置
分数可以配置不显示
页面销毁前播放音频
parent 785ff202
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.replayHotZoneIndex]); this.setReplayBtn(this.data.hotZoneItemArr[this.data.submitHotZoneIndex]);
// 检查是否可以提交 // 检查是否可以提交
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, highlightColor); cc.Color.fromHEX(color, maskColor);
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) {},
} }
This diff is collapsed.
...@@ -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) => {
......
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