Commit aef36fe4 authored by Tt's avatar Tt

基础逻辑完成,构建整体的逻辑顺序即可

parent aff5e241
......@@ -2,6 +2,7 @@ class Card {
constructor(picItem, cardId) {
this.cardId = cardId;
this.type = CardManager.TYPE_IMG;
this.right = picItem.radioValue == "1";
this.img = picItem.pic_url;
this.audio = picItem.audio_url;
}
......
This source diff could not be displayed because it is too large. You can view the blob instead.
......@@ -170,7 +170,6 @@ cc.Class({
this.btn_replay = pg.view.find(this, "btn_replay");
pg.view.visible(this.btn_replay, false);
pg.view.touchOn(this.btn_replay, this.onTouchReplay, this);
this.initStars();
this.initLayout();
},
initStars() {
......@@ -179,16 +178,15 @@ cc.Class({
},
initLayout() {
pg.view.visible(this.btn_replay, false);
pg.view.visible(pg.view.find(this, `layout_card_4`), false);
pg.view.visible(pg.view.find(this, `layout_card_6`), false);
pg.view.visible(pg.view.find(this, `layout_card_8`), false);
pg.view.visible(pg.view.find(this, `layout_card_10`), false);
this._cardLayout = pg.view.find(this, `layout_card_${this._cardPage.length}`);
this._cardLayout = pg.view.find(this, `layout_card_6`);
ani.scaleIn(this._cardLayout);
pg.view.visible(this._cardLayout, true);
let itemBase = pg.view.find(this, "item");
for (let i = 0; i < this._cardPage.length; i++) {
let data = this._cardPage[i];
let item = pg.view.find(this._cardLayout, `item_${i}`);
let item = cc.instantiate(itemBase)
item.parent = this._cardLayout;
if (!data || !item || data.type == CardManager.TYPE_NULL) continue;
this.updateItem(item, data);
}
......@@ -198,90 +196,39 @@ cc.Class({
let txt = pg.view.find(item, `txt`);
let audio = pg.view.find(item, `audio`);
let box = pg.view.find(item, `box`);
console.log(CardManager.TYPE_IMG);
if (data.type == CardManager.TYPE_IMG) {
pg.view.setNetImg(img, data.img);
pg.view.visible(img, true);
pg.view.visible(txt, false);
pg.view.visible(audio, false);
} else if (data.type == CardManager.TYPE_TXT) {
pg.view.setString(txt, data.txt);
pg.view.visible(img, false);
pg.view.visible(txt, true);
pg.view.visible(audio, false);
} else if (data.type == CardManager.TYPE_MP3) {
pg.view.visible(img, false);
pg.view.visible(txt, false);
pg.view.visible(audio, true);
pg.view.visible(pg.view.find(item, `audio/btn_laba`), true);
}
pg.view.visible(pg.view.find(audio, "icon_1"), false);
pg.view.visible(pg.view.find(audio, "icon_2"), false);
pg.view.visible(pg.view.find(audio, "icon_3"), false);
item.scaleX = 1;
item.scaleY = 1;
pg.view.visible(box, false);
item.attr({ data: data });
pg.view.visible(item, true);
pg.view.touchOn(item, this.onTouchItem, this);
pg.view.touchOn(audio, this.onTouchAudio, this);
},
onTouchItem(touch, info) {
onTouchAudio(touch) {
if (!this._cantouch) return;
this._cantouch = false;
let item = touch.target;
let item = touch.target.parent;
let data = item.data;
console.log(data);
this._cardTouchItems.push(item);
if (this._cardTouchItems.length == 2) {
let item0 = this._cardTouchItems[0];
let item1 = this._cardTouchItems[1];
//检测重复点击 取消选中
if (item0.data && item1.data && item0.data.cardId == item1.data.cardId) {
pg.view.visible(pg.view.find(item, 'box'), false);
this._cantouch = true;
} else if (item0.data && item1.data && item0.data.cardDid == item1.data.cardDid) {
//成功--变小 消失
this._successItems.push(item0);
this._successItems.push(item1);
pg.view.visible(pg.view.find(item, 'box'), true);
this.playSFX("audio_choice").then(() => {
this.playAudioAni(item).then(() => {
this.createRightAni(cc.v2(item0.x, item0.y));
this.createRightAni(cc.v2(item1.x, item1.y));
this.playSFX("audio_right").then(() => {
this._cantouch = true;
this.playAudioAni(item0).then(() => {
this.playAudioAni(item1).then(() => {
ani.scaleOut(item0);
ani.scaleOut(item1).then(() => {
setTimeout(() => {
this.groupEnd();//判定单组结束
}, 100);
});
pg.view.visible(pg.view.find(item0, 'box'), false);
pg.view.visible(pg.view.find(item1, 'box'), false);
});
});
});
})
});
} else {
//失败--抖动效果
pg.view.visible(pg.view.find(item, 'box'), true);
this.playSFX("audio_choice").then(() => {
this.playAudioAni(item).then(() => {
ani.shake(item0);
ani.shake(item1);
pg.view.visible(pg.view.find(item0, 'box'), false);
pg.view.visible(pg.view.find(item1, 'box'), false);
this.playSFX("audio_error").then(() => {
this._cantouch = true;
});
});
});
}
this._cardTouchItems.length = 0;
} else if (this._cardTouchItems.length == 1) {
//显示选中效果
},
onTouchItem(touch, info) {
if (!this._cantouch) return;
this._cantouch = false;
let item = touch.target;
let data = item.data;
if (data.right) {
pg.view.visible(pg.view.find(item, 'box'), true);
this.playSFX("audio_choice").then(() => {
this.playSFX("audio_right").then(() => {
//audio 播放的时候动画播放, audio停的时候 动画正好能停下
//如果动画停的位置不对,直接强制设置对应的效果
//下一次播放没有问题即可
......@@ -290,19 +237,94 @@ cc.Class({
})
});
} else {
//异常情况
this._cardTouchItems.length = 0;
//失败--抖动效果
ani.shake(item);
// this.playAudioAni(item).then(() => {
// });
this.playSFX("audio_error").then(() => {
this._cantouch = true;
});
}
// this._cardTouchItems.push(item);
// if (this._cardTouchItems.length == 2) {
// let item0 = this._cardTouchItems[0];
// let item1 = this._cardTouchItems[1];
// //检测重复点击 取消选中
// if (item0.data && item1.data && item0.data.cardId == item1.data.cardId) {
// pg.view.visible(pg.view.find(item, 'box'), false);
// this._cantouch = true;
// } else if (item0.data && item1.data && item0.data.cardDid == item1.data.cardDid) {
// //成功--变小 消失
// this._successItems.push(item0);
// this._successItems.push(item1);
// pg.view.visible(pg.view.find(item, 'box'), true);
// this.playSFX("audio_choice").then(() => {
// this.playAudioAni(item).then(() => {
// this.createRightAni(cc.v2(item0.x, item0.y));
// this.createRightAni(cc.v2(item1.x, item1.y));
// this.playSFX("audio_right").then(() => {
// this._cantouch = true;
// this.playAudioAni(item0).then(() => {
// this.playAudioAni(item1).then(() => {
// ani.scaleOut(item0);
// ani.scaleOut(item1).then(() => {
// setTimeout(() => {
// this.groupEnd();//判定单组结束
// }, 100);
// });
// pg.view.visible(pg.view.find(item0, 'box'), false);
// pg.view.visible(pg.view.find(item1, 'box'), false);
// });
// });
// });
// })
// });
// } else {
// //失败--抖动效果
// pg.view.visible(pg.view.find(item, 'box'), true);
// this.playSFX("audio_choice").then(() => {
// this.playAudioAni(item).then(() => {
// ani.shake(item0);
// ani.shake(item1);
// pg.view.visible(pg.view.find(item0, 'box'), false);
// pg.view.visible(pg.view.find(item1, 'box'), false);
// this.playSFX("audio_error").then(() => {
// this._cantouch = true;
// });
// });
// });
// }
// this._cardTouchItems.length = 0;
// } else if (this._cardTouchItems.length == 1) {
// //显示选中效果
// pg.view.visible(pg.view.find(item, 'box'), true);
// this.playSFX("audio_choice").then(() => {
// //audio 播放的时候动画播放, audio停的时候 动画正好能停下
// //如果动画停的位置不对,直接强制设置对应的效果
// //下一次播放没有问题即可
// this.playAudioAni(item).then(() => {
// this._cantouch = true;
// })
// });
// } else {
// //异常情况
// this._cardTouchItems.length = 0;
// this._cantouch = true;
// }
},
playAudioAni(item) {
return new Promise((resolve, reject) => {
var anim = pg.view.find(item, `audio`).getComponent(cc.Animation);
anim.play();
// var anim = pg.view.find(item, `audio`).getComponent(cc.Animation);
// anim.play();
let audio = pg.view.find(item, `audio`);
let icon_1 = pg.view.find(audio, "icon_1");
let icon_2 = pg.view.find(audio, "icon_2");
let icon_3 = pg.view.find(audio, "icon_3");
icon_1.active = true;
//如果没有audio也要能正常走
pg.audio.playAudioByUrl(item.data.audio).then(() => {
anim.stop();
pg.view.visible(pg.view.find(item, `audio/btn_laba`), true);
// anim.stop();
icon_1.active = false;
resolve('');
});
});
......@@ -550,163 +572,4 @@ cc.Class({
return quadBase;
},
// audioBtn: null,
// initAudio() {
// const audioNode = cc.find('Canvas/res/audio');
// const getAudioByResName = (resName) => {
// return audioNode.getChildByName(resName).getComponent(cc.AudioSource);
// }
// this.audioBtn = getAudioByResName('btn');
// },
// initView() {
// this.initBg();
// this.initPic();
// this.initBtn();
// this.initIcon();
// },
// initBg() {
// const bgNode = cc.find('Canvas/bg');
// bgNode.scale = this._mapScaleMax;
// },
// pic1: null,
// pic2: null,
// initPic() {
// const canvas = cc.find('Canvas');
// const maxW = canvas.width * 0.7;
// hyLoader.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);
// });
// hyLoader.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() {
// const iconNode = hyLoader.getSprNode('icon');
// iconNode.zIndex = 5;
// 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, () => {
// hyLoader.playAudioByUrl(this.data.audio_url);
// })
// },
// curPage: null,
// initBtn() {
// 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();
// // 游戏结束时需要调用这个方法通知系统作业完成
// onHomeworkFinish();
// cc.audioEngine.play(this.audioBtn.clip, false, 0.8)
// })
// const rightBtnNode = bottomPart.getChildByName('btn_right');
// //节点中添加了button组件 则可以添加click事件监听
// rightBtnNode.on('click', () => {
// if (!this._cantouch) {
// return;
// }
// if (this.curPage == 1) {
// return;
// }
// this.curPage = 1
// this.rightMove();
// cc.audioEngine.play(this.audioBtn.clip, false, 0.5)
// })
// },
// leftMove() {
// this._cantouch = false;
// const len = this.pic1.parent.width;
// 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() {
// this._cantouch = false;
// const len = this.pic1.parent.width;
// cc.tween(this.pic1)
// .to(1, { x: this.pic1.baseX - len }, { easing: 'cubicInOut' })
// .start();
// cc.tween(this.pic2)
// .to(1, { x: this.pic2.baseX - len }, { easing: 'cubicInOut' })
// .call(() => {
// this._cantouch = true;
// })
// .start();
// },
// update (dt) {},
// ------------------------------------------
});
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