Commit 59a6c521 authored by 章红平's avatar 章红平

提交

parent a2a9bcde
...@@ -59,6 +59,7 @@ export default class card extends cc.Component { ...@@ -59,6 +59,7 @@ export default class card extends cc.Component {
playDragon(cb){ playDragon(cb){
return new Promise((resolve,reject)=>{ return new Promise((resolve,reject)=>{
this.dragon.node.active=true; this.dragon.node.active=true;
this.dragon.node.scaleX=this.node.scaleX;
this.dragon.playAnimation("newAnimation", 1) this.dragon.playAnimation("newAnimation", 1)
this.dragon.on(dragonBones.EventObject.COMPLETE,()=>{ this.dragon.on(dragonBones.EventObject.COMPLETE,()=>{
if(cb){ if(cb){
...@@ -98,7 +99,7 @@ export default class card extends cc.Component { ...@@ -98,7 +99,7 @@ export default class card extends cc.Component {
.start(); .start();
}else{ }else{
cc.tween(this.node) cc.tween(this.node)
.to(0.25,{scaleX:0}) .to(0.25,{scaleX:0.3})
.call(()=>{ .call(()=>{
this.iconN.scaleX=-this.iconN.scaleX this.iconN.scaleX=-this.iconN.scaleX
this.wordLabel.node.scaleX=1 this.wordLabel.node.scaleX=1
......
...@@ -916,7 +916,7 @@ ...@@ -916,7 +916,7 @@
{ {
"__type__": "cc.Node", "__type__": "cc.Node",
"_name": "New Label", "_name": "New Label",
"_objFlags": 0, "_objFlags": 512,
"_parent": { "_parent": {
"__id__": 16 "__id__": 16
}, },
...@@ -1531,7 +1531,7 @@ ...@@ -1531,7 +1531,7 @@
{ {
"__type__": "cc.Node", "__type__": "cc.Node",
"_name": "card", "_name": "card",
"_objFlags": 0, "_objFlags": 512,
"_parent": { "_parent": {
"__id__": 29 "__id__": 29
}, },
...@@ -3870,9 +3870,9 @@ ...@@ -3870,9 +3870,9 @@
"_opacity": 255, "_opacity": 255,
"_color": { "_color": {
"__type__": "cc.Color", "__type__": "cc.Color",
"r": 255, "r": 246,
"g": 255, "g": 199,
"b": 255, "b": 166,
"a": 255 "a": 255
}, },
"_contentSize": { "_contentSize": {
...@@ -5349,7 +5349,7 @@ ...@@ -5349,7 +5349,7 @@
"__id__": 2 "__id__": 2
}, },
"_children": [], "_children": [],
"_active": true, "_active": false,
"_components": [ "_components": [
{ {
"__id__": 125 "__id__": 125
...@@ -5366,7 +5366,7 @@ ...@@ -5366,7 +5366,7 @@
}, },
"_contentSize": { "_contentSize": {
"__type__": "cc.Size", "__type__": "cc.Size",
"width": 97.87, "width": 0,
"height": 50.4 "height": 50.4
}, },
"_anchorPoint": { "_anchorPoint": {
...@@ -5418,8 +5418,8 @@ ...@@ -5418,8 +5418,8 @@
], ],
"_srcBlendFactor": 770, "_srcBlendFactor": 770,
"_dstBlendFactor": 771, "_dstBlendFactor": 771,
"_string": "Label", "_string": "",
"_N$string": "Label", "_N$string": "",
"_fontSize": 40, "_fontSize": 40,
"_lineHeight": 40, "_lineHeight": 40,
"_enableWrapText": true, "_enableWrapText": true,
......
...@@ -16,18 +16,18 @@ export default class SceneComponent extends MyCocosSceneComponent { ...@@ -16,18 +16,18 @@ export default class SceneComponent extends MyCocosSceneComponent {
@property(cc.Node) @property(cc.Node)
tipN: cc.Node = null tipN: cc.Node = null
@property(cc.Node) @property(cc.Node)
countDown:cc.Node=null; countDown: cc.Node = null;
questionIndex = 0; questionIndex = 0;
gameState="watching" gameState = "watching"
watchInterval=null; watchInterval = null;
gameInterval=null; gameInterval = null;
watchTime=null; watchTime = null;
gameTime=null; gameTime = null;
clickNode1:cc.Node=null; clickNode1: cc.Node = null;
clickNodeData1=null clickNodeData1 = null
canTouch=false canTouch = false
completeNum=0; completeNum = 0;
...@@ -51,21 +51,24 @@ export default class SceneComponent extends MyCocosSceneComponent { ...@@ -51,21 +51,24 @@ export default class SceneComponent extends MyCocosSceneComponent {
} }
start(): void { start(): void {
this.cardParentN.removeAllChildren();
cc.find("Canvas/uiP/bg_tip").active=false;
super.start(); super.start();
this.log('initBg:' ); this.log('initBg:');
this.initBg(); this.initBg();
this.cardParentN.removeAllChildren();
// this.initData(); // this.initData();
// cc.find("Canvas/uiP/top/timeN").active=false; // cc.find("Canvas/uiP/top/timeN").active=false;
} }
_cantouch = null; _cantouch = null;
initData() { initData() {
this.log('initData:' ); this.log('initData:');
// 所有全局变量 默认都是null // 所有全局变量 默认都是null
cc.find("Canvas/uiP/bg_tip").active=true;
this.tittleLabel.string = this.data.title; this.tittleLabel.string = this.data.title;
this.tipLabel.string = this.data.questionText; this.tipLabel.string = this.data.questionText;
this.initCards() this.initCards()
// this.initTime();
} }
...@@ -76,47 +79,49 @@ export default class SceneComponent extends MyCocosSceneComponent { ...@@ -76,47 +79,49 @@ export default class SceneComponent extends MyCocosSceneComponent {
// cc.find('Canvas/uiP/top').y=this._frameSize.height/4; // cc.find('Canvas/uiP/top').y=this._frameSize.height/4;
} }
initCards() { initCards() {
let data=this.getRandomCardData(); let data = this.getRandomCardData();
console.log("getRandomCardData==========", data)
let num = data.length; let num = data.length;
this.cardParentN.removeAllChildren(); this.cardParentN.removeAllChildren();
let col = Math.ceil(num / 2); let col = Math.ceil(num / 2);
let width = 1250; let width = 1250;
if(num<=8)width=1050 console.log("getRandomCardData==========col", col,num)
if (num <= 8) width = 1050
if (col > 2) { if (col > 2) {
for (let i = 0; i < num; i++) { for (let i = 0; i < num; i++) {
let card = cc.instantiate(this.cardP); let card = cc.instantiate(this.cardP);
this.cardParentN.addChild(card) this.cardParentN.addChild(card)
let indexCol = Math.floor(i / 2); let indexCol = Math.floor(i / 2);
let space = width / col; let space = width / col;
card.x = -width/2 + space * (indexCol + 1 / 2); card.x = -width / 2 + space * (indexCol + 1 / 2);
if (i % 2 == 1) { if (i % 2 == 1) {
card.y = -card.height / 2 - 10 card.y = -card.height / 2 - 10
} else { } else {
card.y = +card.height / 2 + 10 card.y = +card.height / 2 + 10
} }
card.getComponent("card").initData(data[i],this) card.getComponent("card").initData(data[i], this)
} }
} else if (col == 2) { } else if (col == 2) {
for (let i = 0; i < num; i++) { for (let i = 0; i < num; i++) {
let card = cc.instantiate(this.cardP); let card = cc.instantiate(this.cardP);
this.cardParentN.addChild(card) this.cardParentN.addChild(card)
if (Math.floor(i / 2) > 0) { if (Math.floor(i / 2) > 0) {
card.x = -180 card.x = -180
} else { } else {
card.x = 180 card.x = 180
} }
if (i % 2 == 1) { if (i % 2 == 1) {
card.y = -card.height / 2 - 10 card.y = -card.height / 2 - 10
} else { } else {
card.y = +card.height / 2 + 10 card.y = +card.height / 2 + 10
} }
card.getComponent("card").initData(data[i],this) card.getComponent("card").initData(data[i], this)
} }
} else { } else {
for (let i = 0; i < num; i++) { for (let i = 0; i < num; i++) {
let card = cc.instantiate(this.cardP); let card = cc.instantiate(this.cardP);
this.cardParentN.addChild(card) this.cardParentN.addChild(card)
...@@ -126,9 +131,10 @@ export default class SceneComponent extends MyCocosSceneComponent { ...@@ -126,9 +131,10 @@ export default class SceneComponent extends MyCocosSceneComponent {
} else { } else {
card.y = +card.height / 2 + 10 card.y = +card.height / 2 + 10
} }
card.getComponent("card").initData(data[i],this) card.getComponent("card").initData(data[i], this)
} }
} }
console.log(" this.cardParentN=====", this.cardParentN)
} }
getRandomCardData() { getRandomCardData() {
let data = this.data.questions[this.questionIndex].options; let data = this.data.questions[this.questionIndex].options;
...@@ -140,154 +146,173 @@ export default class SceneComponent extends MyCocosSceneComponent { ...@@ -140,154 +146,173 @@ export default class SceneComponent extends MyCocosSceneComponent {
data[a] = data2; data[a] = data2;
data[b] = data1 data[b] = data1
} }
return data return data
} }
initTime(){ initTime() {
// cc.find("Canvas/uiP/top/timeN").active=true; // cc.find("Canvas/uiP/top/timeN").active=true;
let timeN=cc.find("Canvas/uiP/top/timeN/bg_time"); let timeN = cc.find("Canvas/uiP/top/timeN/bg_time");
let timeN1=cc.find("Canvas/uiP/top/timeN/bg_time2"); let timeN1 = cc.find("Canvas/uiP/top/timeN/bg_time2");
this.watchTime=this.data.questions[0].watchTime; this.watchTime = this.data.questions[0].watchTime;
this.gameTime=this.data.questions[0].gameTime; this.gameTime = this.data.questions[0].gameTime;
let numTime= this.watchTime; let numTime = this.watchTime;
if(this.gameState=="game")numTime=this.gameTime; if (this.gameState == "game") numTime = this.gameTime;
timeN.getComponentInChildren(cc.Label).string=numTime; timeN.getComponentInChildren(cc.Label).string = numTime;
timeN.active=true; timeN.active = true;
timeN1.active=false; timeN1.active = false;
} }
updateTime(){ updateTime() {
let timeN=cc.find("Canvas/uiP/top/timeN/bg_time"); let timeN = cc.find("Canvas/uiP/top/timeN/bg_time");
let timeN1=cc.find("Canvas/uiP/top/timeN/bg_time2"); let timeN1 = cc.find("Canvas/uiP/top/timeN/bg_time2");
let numTime=this.watchTime; let numTime = this.watchTime;
if(this.gameState=="game")numTime=this.gameTime; if (this.gameState == "game") numTime = this.gameTime;
timeN.getComponentInChildren(cc.Label).string=numTime; timeN.getComponentInChildren(cc.Label).string = numTime;
timeN1.getComponentInChildren(cc.Label).string=numTime; timeN1.getComponentInChildren(cc.Label).string = numTime;
timeN.active=true; timeN.active = true;
timeN1.active=false; timeN1.active = false;
if(numTime<=5){ if (numTime <= 5) {
timeN.active=false; timeN.active = false;
timeN1.active=true; timeN1.active = true;
// if(this.gameState=="game"){ // if(this.gameState=="game"){
if(numTime<=1){ if (numTime <= 1) {
if(numTime==1)this.playLocalAudio("time1") if (numTime == 1) this.playLocalAudio("time1")
}else{ } else {
this.playLocalAudio("time2") this.playLocalAudio("time2")
} }
// }else{ // }else{
if(this.gameState=="watching"){ if (this.gameState == "watching") {
if(numTime==1||numTime==2||numTime==3){ if (numTime == 1 || numTime == 2 || numTime == 3) {
this.countDown.active=true; this.countDown.active = true;
this.countDown.stopAllActions(); this.countDown.stopAllActions();
this.countDown.scale=1; this.countDown.scale = 1;
this.getSprforNode(numTime, this.countDown); this.getSprforNode(numTime, this.countDown);
cc.tween( this.countDown) cc.tween(this.countDown)
.to(0.8,{scale:0.7}) .to(0.8, { scale: 0.7 })
.call(()=>{ .call(() => {
this.countDown.active=false; this.countDown.active = false;
}) })
.start() .start()
}
} }
}
// } // }
} }
} }
onStartClick(){ onStartClick() {
this.tipN.active=false; this.tipN.active = false;
this.playLocalAudio("btn"); this.playLocalAudio("btn");
let children=this.cardParentN.children; let children = this.cardParentN.children;
for(let i=0;i<children.length;i++){ for (let i = 0; i < children.length; i++) {
children[i].getComponent("card").asyncDoFlip(()=>{ children[i].getComponent("card").asyncDoFlip(() => {
if(i==children.length-1)this.startWatch(); if (i == children.length - 1) this.startWatch();
}) })
} }
} }
startWatch(){ startWatch() {
this.canTouch=false this.canTouch = false
this.gameState=="watching" this.gameState == "watching"
this.clearntervals(); this.clearntervals();
this.initTime(); this.initTime();
this.watchInterval=setInterval(()=>{ this.watchInterval = setInterval(() => {
this.watchTime--; this.watchTime--;
console.log("watchtime=====",this.watchTime) console.log("watchtime=====", this.watchTime)
if( this.watchTime<=0){ if (this.watchTime <= 0) {
this.clearntervals(); this.clearntervals();
let children=this.cardParentN.children; let children = this.cardParentN.children;
for(let i=0;i<children.length;i++){ for (let i = 0; i < children.length; i++) {
children[i].getComponent("card").asyncDoFlip(()=>{ children[i].getComponent("card").asyncDoFlip(() => {
if(i==children.length-1)this.startGame(); if (i == children.length - 1) this.startGame();
}) })
} }
} }
this.updateTime(); this.updateTime();
},1000) }, 1000)
}; };
startGame(){ startGame() {
this.canTouch=true; this.canTouch = true;
this.gameState="game" this.gameState = "game"
this.clearntervals(); this.clearntervals();
this.initTime(); this.initTime();
this.gameInterval=setInterval(()=>{ this.gameInterval = setInterval(() => {
this.gameTime--; this.gameTime--;
console.log("watchtime=====",this.gameTime) console.log("watchtime=====", this.gameTime)
if( this.gameTime<=0){ if (this.gameTime <= 0) {
this.clearntervals(); this.clearntervals();
} }
this.updateTime(); this.updateTime();
},1000) }, 1000)
} }
clickCard(node,data){ clickCard(node, data) {
if(this.canTouch){ if (this.canTouch) {
if(!this.clickNode1){ if (!this.clickNode1) {
this.clickNode1=node; this.clickNode1 = node;
this.clickNodeData1=data; this.clickNodeData1 = data;
this.clickNode1.getComponent("card").asyncDoFlip() this.clickNode1.getComponent("card").asyncDoFlip()
this.playAudioByUrl( this.clickNodeData1.audio); this.playAudioByUrl(this.clickNodeData1.audio);
}else{ } else {
if(this.clickNode1==node){ if (this.clickNode1 == node) {
return; return;
// this.playAudioByUrl( this.clickNodeData1.audio); // this.playAudioByUrl( this.clickNodeData1.audio);
}else{ } else {
this.canTouch=false this.canTouch = false
Promise if (this.clickNodeData1.pairIdx == data.pairIdx) {
.all([node.getComponent("card").asyncDoFlip(), this.playAudioByUrl( data.audio)]) Promise
.then(()=>{ .all([node.getComponent("card").asyncDoFlip(), this.playAudioByUrl(data.audio)])
Promise.all([node.getComponent("card").playDragon(), this.clickNode1.getComponent("card").playDragon(),this.playLocalAudio("true")]) .then(() => {
.then(()=>{ Promise.all([node.getComponent("card").playDragon(), this.clickNode1.getComponent("card").playDragon(), this.playLocalAudio("true")])
Promise.all([node.getComponent("card").doHide(), this.clickNode1.getComponent("card").doHide()]) .then(() => {
.then(()=>{ Promise.all([node.getComponent("card").doHide(), this.clickNode1.getComponent("card").doHide()])
this.canTouch=true; .then(() => {
this.clickNode1=null this.canTouch = true;
this.clickNodeData1=null; this.clickNode1 = null
this.completeNum++ this.clickNodeData1 = null;
if(this.completeNum== this.data.questions[this.questionIndex].options.length/2){ this.completeNum++
console.log("allTrue===") if (this.completeNum == this.data.questions[this.questionIndex].options.length / 2) {
this.clearntervals(); console.log("allTrue===")
} this.clearntervals();
console.log("allActionFish=====") }
}) console.log("allActionFish=====")
}) })
})
}
)
} else {
Promise
.all([node.getComponent("card").asyncDoFlip(), this.playAudioByUrl(data.audio)])
.then(() => {
Promise.all([this.playLocalAudio("false")])
.then(() => {
Promise.all([node.getComponent("card").asyncDoFlip(), this.clickNode1.getComponent("card").asyncDoFlip()])
.then(() => {
this.canTouch = true;
this.clickNode1 = null
this.clickNodeData1 = null;
})
})
}
)
} }
)
} }
} }
} }
} }
clearntervals(){ clearntervals() {
// cc.find("Canvas/uiP/top/timeN").active=false; // cc.find("Canvas/uiP/top/timeN").active=false;
if(this.watchInterval){ if (this.watchInterval) {
clearInterval(this.watchInterval); clearInterval(this.watchInterval);
} }
if(this.gameInterval){ if (this.gameInterval) {
clearInterval(this.gameInterval); clearInterval(this.gameInterval);
} }
} }
......
...@@ -118,6 +118,7 @@ export class MyCocosSceneComponent extends cc.Component { ...@@ -118,6 +118,7 @@ export class MyCocosSceneComponent extends cc.Component {
const node = cc.find('Canvas/middleLayer'); const node = cc.find('Canvas/middleLayer');
if (node) { if (node) {
node.getComponent(cc.Label).string=str; node.getComponent(cc.Label).string=str;
console.log(str);
} else { } else {
console.log(str); console.log(str);
} }
......
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