Commit c5832a8f authored by 李维's avatar 李维

Done

parent ab33b3cf
...@@ -5,16 +5,24 @@ const { ccclass, property } = cc._decorator; ...@@ -5,16 +5,24 @@ const { ccclass, property } = cc._decorator;
@ccclass @ccclass
export default class SceneComponent extends MyCocosSceneComponent { export default class SceneComponent extends MyCocosSceneComponent {
@property({type: cc.Node, displayName: "开始按钮"})
startBtn: cc.Node = null;
@property({type: cc.Node, displayName: "结束按钮"})
stopBtn: cc.Node = null;
@property({type: cc.Node, displayName: "复制信息"})
copyInfoBtn: cc.Node = null;
@property({type: cc.Node, displayName: "信息输出"})
outputBox: cc.Node = null;
addPreloadImage() { addPreloadImage() {
// TODO 根据自己的配置预加载图片资源 // TODO 根据自己的配置预加载图片资源
this._imageResList.push({ url: this.data.pic_url });
this._imageResList.push({ url: this.data.pic_url_2 });
} }
addPreloadAudio() { addPreloadAudio() {
// TODO 根据自己的配置预加载音频资源 // TODO 根据自己的配置预加载音频资源
this._audioResList.push({ url: this.data.audio_url });
} }
addPreloadAnima() { addPreloadAnima() {
...@@ -23,22 +31,21 @@ export default class SceneComponent extends MyCocosSceneComponent { ...@@ -23,22 +31,21 @@ export default class SceneComponent extends MyCocosSceneComponent {
async onLoadEnd() { async onLoadEnd() {
// TODO 加载完成后的逻辑写在这里, 下面的代码仅供参考 // TODO 加载完成后的逻辑写在这里, 下面的代码仅供参考
this.initData();
this.initView(); this.initView();
this.initListener(); this.initListener();
} }
_cantouch = null; comTotal = null;
initData() { comSuccess = null;
// 所有全局变量 默认都是null comFail = null;
this._cantouch = true;
}
initView() { initView() {
this.initBg(); this.initBg();
this.initPic();
this.initBtn(); this.initBtn();
this.initIcon(); this.comTotal = cc.find("Canvas/rightSummaryInfo/total").getComponent(cc.Label);
this.comSuccess = cc.find("Canvas/rightSummaryInfo/success").getComponent(cc.Label);
this.comFail = cc.find("Canvas/rightSummaryInfo/fail").getComponent(cc.Label);
this.initData();
} }
initBg() { initBg() {
...@@ -51,131 +58,70 @@ export default class SceneComponent extends MyCocosSceneComponent { ...@@ -51,131 +58,70 @@ export default class SceneComponent extends MyCocosSceneComponent {
initPic() { initPic() {
const canvas = cc.find('Canvas'); const canvas = cc.find('Canvas');
const maxW = canvas.width * 0.7; const maxW = canvas.width * 0.7;
this.getSprNodeByUrl(this.data.pic_url, (sprNode) => {
const picNode1 = sprNode;
picNode1.scale = maxW / picNode1.width;
picNode1.baseX = picNode1.x;
canvas.addChild(picNode1);
this.pic1 = picNode1;
const labelNode = new cc.Node();
labelNode.color = cc.Color.YELLOW;
const label = labelNode.addComponent(cc.Label);
label.string = this.data.text;
label.fontSize = 60;
label.lineHeight = 60;
label.font = cc.find('Canvas/res/font/BRLNSDB').getComponent('cc.Label').font;
picNode1.addChild(labelNode);
});
this.getSprNodeByUrl(this.data.pic_url_2, (sprNode) => {
const picNode2 = sprNode;
picNode2.scale = maxW / picNode2.width;
canvas.addChild(picNode2);
picNode2.x = canvas.width;
picNode2.baseX = picNode2.x;
this.pic2 = picNode2;
const labelNode = new cc.Node();
const label = labelNode.addComponent(cc.RichText);
const size = 60
label.font = cc.find('Canvas/res/font/BRLNSDB').getComponent(cc.Label).font;
label.string = `<outline color=#751e00 width=4><size=${size}><color=#ffffff>${this.data.text}</color></size></outline>`
label.lineHeight = size;
picNode2.addChild(labelNode);
});
} }
initIcon() { initBtn() {
const iconNode = this.getSprNode('icon'); this.startBtn.on("click", ()=>{
iconNode.zIndex = 5; this.startCheck();
iconNode.anchorX = 1;
iconNode.anchorY = 1;
iconNode.parent = cc.find('Canvas');
iconNode.x = iconNode.parent.width / 2 - 10;
iconNode.y = iconNode.parent.height / 2 - 10;
iconNode.on(cc.Node.EventType.TOUCH_START, () => {
this.playAudioByUrl(this.data.audio_url);
}) })
} }
curPage = null; initData() {
initBtn() { console.log(this.data);
}
this.curPage = 0;
const bottomPart = cc.find('Canvas/bottomPart');
bottomPart.zIndex = 5; // 提高层级
bottomPart.x = bottomPart.parent.width / 2;
bottomPart.y = -bottomPart.parent.height / 2;
const leftBtnNode = bottomPart.getChildByName('btn_left');
//节点中添加了button组件 则可以添加click事件监听
leftBtnNode.on('click', () => {
if (!this._cantouch) {
return;
}
if (this.curPage == 0) {
return;
}
this.curPage = 0
this.leftMove();
this.playLocalAudio('btn'); async startCheck() {
}) const audioUrl = [];
this.data.forEach(item => {
audioUrl.push({
id: item.id,
type: "cn",
name: item.text_cn,
audio_url: item.audio_cn_url
})
audioUrl.push({
id: item.id,
type: "en",
name: item.text_en,
audio_url: item.audio_url
})
});
const rightBtnNode = bottomPart.getChildByName('btn_right'); this.summaryInfo_now = 0;
//节点中添加了button组件 则可以添加click事件监听 this.summaryInfo_total = audioUrl.length;
rightBtnNode.on('click', () => { this.summaryInfo_success = 0;
if (!this._cantouch) { this.summaryInfo_fail = 0;
return; this.updateSummaryInfo()
} for(let i=0; i<audioUrl.length; i++) {
if (this.curPage == 1) { const res = await this.testAudioPlay(audioUrl[i].audio_url)
return; if(res) {
this.inputText(`播放成功! id:${audioUrl[i].id} 资源名:${audioUrl[i].name}`);
this.summaryInfo_success ++;
} else {
this.inputText(`播放失败! id:${audioUrl[i].id} 资源名:${audioUrl[i].name}`);
console.log(`Fail: id=${audioUrl[i].id} type=${audioUrl[i].type}`)
this.summaryInfo_fail ++;
} }
this.updateSummaryInfo()
this.curPage = 1 }
this.rightMove(); this.inputText(`检测完成,总计【${this.summaryInfo_total}】 成功【${this.summaryInfo_success}】 失败【${this.summaryInfo_fail}】`);
// 游戏结束时需要调用这个方法通知系统作业完成
onHomeworkFinish();
this.playLocalAudio('btn');
})
} }
leftMove() { // 输入文字
this._cantouch = false; inputText(str) {
const len = this.pic1.parent.width; this.outputBox.getComponent(cc.Label).string = str;
cc.tween(this.pic1)
.to(1, { x: this.pic1.baseX }, { easing: 'cubicInOut' })
.start();
cc.tween(this.pic2)
.to(1, { x: this.pic2.baseX }, { easing: 'cubicInOut' })
.call(() => {
this._cantouch = true;
})
.start();
} }
rightMove() { summaryInfo_now = 0;
this._cantouch = false; summaryInfo_total = 0;
const len = this.pic1.parent.width; summaryInfo_success = 0;
cc.tween(this.pic1) summaryInfo_fail = 0;
.to(1, { x: this.pic1.baseX - len }, { easing: 'cubicInOut' }) updateSummaryInfo() {
.start(); this.comTotal.string = `进度:${this.summaryInfo_now}/${this.summaryInfo_total}`
this.comSuccess.string = `成功:${this.summaryInfo_success}`
cc.tween(this.pic2) this.comFail.string = `失败:${this.summaryInfo_fail}`
.to(1, { x: this.pic2.baseX - len }, { easing: 'cubicInOut' })
.call(() => {
this._cantouch = true;
})
.start();
} }
// update (dt) {}, // update (dt) {},
...@@ -192,4 +138,33 @@ export default class SceneComponent extends MyCocosSceneComponent { ...@@ -192,4 +138,33 @@ export default class SceneComponent extends MyCocosSceneComponent {
}); });
}) })
} }
_intervalId = null;
testAudioPlay(audio_url) {
return new Promise((resovle, reject) => {
cc.assetManager.loadRemote(audio_url, (err, audioClip) => {
const audioId = cc.audioEngine.play(audioClip, false, 0.8);
if(this._intervalId != null) {
clearInterval(this._intervalId);
this._intervalId = null;
}
let count = 0;
this._intervalId = setInterval(() => {
if(cc.audioEngine.getCurrentTime(audioId) > 0) {
clearInterval(this._intervalId);
this._intervalId = null;
resovle(true)
} else {
if(count > 50) {
clearInterval(this._intervalId);
this._intervalId = null;
resovle(false)
} else {
count++
}
}
}, 200);
});
})
}
} }
{
"ver": "2.3.5",
"uuid": "efa5fa09-a4dd-4bfc-ab7e-17c19f85408f",
"type": "sprite",
"wrapMode": "clamp",
"filterMode": "bilinear",
"premultiplyAlpha": false,
"genMipmaps": false,
"packable": true,
"width": 366,
"height": 336,
"platformSettings": {},
"subMetas": {
"1orange": {
"ver": "1.0.4",
"uuid": "43d1e79d-6de8-4dcb-b8ce-d767df7913aa",
"rawTextureUuid": "efa5fa09-a4dd-4bfc-ab7e-17c19f85408f",
"trimType": "auto",
"trimThreshold": 1,
"rotated": false,
"offsetX": 0,
"offsetY": -0.5,
"trimX": 0,
"trimY": 1,
"width": 366,
"height": 335,
"rawWidth": 366,
"rawHeight": 336,
"borderTop": 0,
"borderBottom": 0,
"borderLeft": 0,
"borderRight": 0,
"subMetas": {}
}
}
}
\ No newline at end of file
{ {
"ver": "2.3.5", "ver": "2.3.5",
"uuid": "9a79969a-0506-48d4-bc98-3c05d109b027", "uuid": "75197063-3a11-4d30-b364-6677df12ca0f",
"type": "sprite", "type": "sprite",
"wrapMode": "clamp", "wrapMode": "clamp",
"filterMode": "bilinear", "filterMode": "bilinear",
"premultiplyAlpha": false, "premultiplyAlpha": false,
"genMipmaps": false, "genMipmaps": false,
"packable": true, "packable": true,
"width": 61, "width": 1920,
"height": 67, "height": 1080,
"platformSettings": {}, "platformSettings": {},
"subMetas": { "subMetas": {
"btn_left": { "bg_dark": {
"ver": "1.0.4", "ver": "1.0.4",
"uuid": "ce19457d-e8f3-4c38-ae3e-d4b99208ddb5", "uuid": "d1add30b-0179-4a8b-8826-d6738d26f18f",
"rawTextureUuid": "9a79969a-0506-48d4-bc98-3c05d109b027", "rawTextureUuid": "75197063-3a11-4d30-b364-6677df12ca0f",
"trimType": "auto", "trimType": "auto",
"trimThreshold": 1, "trimThreshold": 1,
"rotated": false, "rotated": false,
...@@ -22,10 +22,10 @@ ...@@ -22,10 +22,10 @@
"offsetY": 0, "offsetY": 0,
"trimX": 0, "trimX": 0,
"trimY": 0, "trimY": 0,
"width": 61, "width": 1920,
"height": 67, "height": 1080,
"rawWidth": 61, "rawWidth": 1920,
"rawHeight": 67, "rawHeight": 1080,
"borderTop": 0, "borderTop": 0,
"borderBottom": 0, "borderBottom": 0,
"borderLeft": 0, "borderLeft": 0,
......
{
"ver": "2.3.5",
"uuid": "d582359e-924e-4ee9-9964-1fc4bb417e71",
"type": "sprite",
"wrapMode": "clamp",
"filterMode": "bilinear",
"premultiplyAlpha": false,
"genMipmaps": false,
"packable": true,
"width": 61,
"height": 67,
"platformSettings": {},
"subMetas": {
"btn_right": {
"ver": "1.0.4",
"uuid": "e5a2dbaa-a677-4a32-90d7-a1b057d7fb59",
"rawTextureUuid": "d582359e-924e-4ee9-9964-1fc4bb417e71",
"trimType": "auto",
"trimThreshold": 1,
"rotated": false,
"offsetX": -0.5,
"offsetY": 0.5,
"trimX": 0,
"trimY": 0,
"width": 60,
"height": 66,
"rawWidth": 61,
"rawHeight": 67,
"borderTop": 0,
"borderBottom": 0,
"borderLeft": 0,
"borderRight": 0,
"subMetas": {}
}
}
}
\ No newline at end of file
{
"ver": "2.3.5",
"uuid": "18d07592-51a9-421e-8972-0f67b68d29e1",
"type": "sprite",
"wrapMode": "clamp",
"filterMode": "bilinear",
"premultiplyAlpha": false,
"genMipmaps": false,
"packable": true,
"width": 144,
"height": 144,
"platformSettings": {},
"subMetas": {
"icon": {
"ver": "1.0.4",
"uuid": "6fbc30a8-3c49-44ae-8ba4-7f56f385b78a",
"rawTextureUuid": "18d07592-51a9-421e-8972-0f67b68d29e1",
"trimType": "auto",
"trimThreshold": 1,
"rotated": false,
"offsetX": 0,
"offsetY": -0.5,
"trimX": 3,
"trimY": 2,
"width": 138,
"height": 141,
"rawWidth": 144,
"rawHeight": 144,
"borderTop": 0,
"borderBottom": 0,
"borderLeft": 0,
"borderRight": 0,
"subMetas": {}
}
}
}
\ No newline at end of file
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