Commit 1592a91a authored by 章红平's avatar 章红平

提交

parent 54d79795
...@@ -25,19 +25,22 @@ ...@@ -25,19 +25,22 @@
}, },
{ {
"__id__": 11 "__id__": 11
},
{
"__id__": 14
} }
], ],
"_active": true, "_active": true,
"_components": [ "_components": [
{ {
"__id__": 14 "__id__": 17
}, },
{ {
"__id__": 15 "__id__": 18
} }
], ],
"_prefab": { "_prefab": {
"__id__": 16 "__id__": 19
}, },
"_opacity": 255, "_opacity": 255,
"_color": { "_color": {
...@@ -89,7 +92,7 @@ ...@@ -89,7 +92,7 @@
{ {
"__type__": "cc.Node", "__type__": "cc.Node",
"_name": "bg_card", "_name": "bg_card",
"_objFlags": 0, "_objFlags": 512,
"_parent": { "_parent": {
"__id__": 1 "__id__": 1
}, },
...@@ -310,7 +313,7 @@ ...@@ -310,7 +313,7 @@
{ {
"__type__": "cc.Node", "__type__": "cc.Node",
"_name": "icon", "_name": "icon",
"_objFlags": 0, "_objFlags": 512,
"_parent": { "_parent": {
"__id__": 1 "__id__": 1
}, },
...@@ -519,6 +522,121 @@ ...@@ -519,6 +522,121 @@
"fileId": "c1uv2eSUhO7ZDzrM1TwY8H", "fileId": "c1uv2eSUhO7ZDzrM1TwY8H",
"sync": false "sync": false
}, },
{
"__type__": "cc.Node",
"_name": "right_ske",
"_objFlags": 0,
"_parent": {
"__id__": 1
},
"_children": [],
"_active": false,
"_components": [
{
"__id__": 15
}
],
"_prefab": {
"__id__": 16
},
"_opacity": 255,
"_color": {
"__type__": "cc.Color",
"r": 255,
"g": 255,
"b": 255,
"a": 255
},
"_contentSize": {
"__type__": "cc.Size",
"width": 136,
"height": 132
},
"_anchorPoint": {
"__type__": "cc.Vec2",
"x": 0.5,
"y": 0.5
},
"_trs": {
"__type__": "TypedArray",
"ctor": "Float64Array",
"array": [
0,
0,
0,
0,
0,
0,
1,
1,
1,
1
]
},
"_eulerAngles": {
"__type__": "cc.Vec3",
"x": 0,
"y": 0,
"z": 0
},
"_skewX": 0,
"_skewY": 0,
"_is3DNode": false,
"_groupIndex": 0,
"groupIndex": 0,
"_id": ""
},
{
"__type__": "dragonBones.ArmatureDisplay",
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 14
},
"_enabled": true,
"_materials": [
{
"__uuid__": "eca5d2f2-8ef6-41c2-bbe6-f9c79d09c432"
}
],
"_armatureName": "Armature",
"_animationName": "",
"_preCacheMode": 0,
"_cacheMode": 0,
"playTimes": -1,
"premultipliedAlpha": false,
"_armatureKey": "97d73a25-19eb-40cd-815d-4c9ee3b688c6#346e8069-b050-46a2-9285-6aa34afce69a",
"_accTime": 0,
"_playCount": 0,
"_frameCache": null,
"_curFrame": null,
"_playing": false,
"_armatureCache": null,
"_N$dragonAsset": {
"__uuid__": "97d73a25-19eb-40cd-815d-4c9ee3b688c6"
},
"_N$dragonAtlasAsset": {
"__uuid__": "346e8069-b050-46a2-9285-6aa34afce69a"
},
"_N$_defaultArmatureIndex": 0,
"_N$_animationIndex": 0,
"_N$_defaultCacheMode": 0,
"_N$timeScale": 1,
"_N$debugBones": false,
"_N$enableBatch": false,
"_id": ""
},
{
"__type__": "cc.PrefabInfo",
"root": {
"__id__": 1
},
"asset": {
"__uuid__": "282fcbdc-d3bf-489b-84b9-56358c5441cb"
},
"fileId": "c5HbFiY0lGdbpsPIcRa1Si",
"sync": false
},
{ {
"__type__": "930ecDU5FRJxY/bSPjAYqS3", "__type__": "930ecDU5FRJxY/bSPjAYqS3",
"_name": "", "_name": "",
...@@ -536,6 +654,9 @@ ...@@ -536,6 +654,9 @@
"wordLabel": { "wordLabel": {
"__id__": 4 "__id__": 4
}, },
"dragon": {
"__id__": 15
},
"_id": "" "_id": ""
}, },
{ {
......
...@@ -16,6 +16,8 @@ export default class card extends cc.Component { ...@@ -16,6 +16,8 @@ export default class card extends cc.Component {
backN: cc.Node = null; backN: cc.Node = null;
@property(cc.Label) @property(cc.Label)
wordLabel: cc.Label = null; wordLabel: cc.Label = null;
@property(dragonBones.ArmatureDisplay)
dragon: dragonBones.ArmatureDisplay = null;
mainControl:SceneComponent=null; mainControl:SceneComponent=null;
data=null data=null
...@@ -24,21 +26,16 @@ export default class card extends cc.Component { ...@@ -24,21 +26,16 @@ export default class card extends cc.Component {
// onLoad () {} // onLoad () {}
start () { start () {
this.node.on("click",()=>{
this.doFlip()
})
} }
initData(data,mainControl){ initData(data,mainControl){
this.data=data; this.data=data;
this.mainControl=mainControl this.mainControl=mainControl
this.node.off("click") this.node.off("click")
this.node.on("click",()=>{ this.node.on("click",(e)=>{
this.doFlip() console.log("e=====",e)
this.mainControl.clickCard(e.node,this.data);
}) })
this.updateBtnAble(false);
if(this.data.type=="img"){ if(this.data.type=="img"){
this.iconN.active=true; this.iconN.active=true;
this.iconN.scaleX=1 this.iconN.scaleX=1
...@@ -59,6 +56,31 @@ export default class card extends cc.Component { ...@@ -59,6 +56,31 @@ export default class card extends cc.Component {
updateBtnAble(interactable){ updateBtnAble(interactable){
this.node.getComponent(cc.Button).interactable=interactable; this.node.getComponent(cc.Button).interactable=interactable;
} }
playDragon(cb){
return new Promise((resolve,reject)=>{
this.dragon.node.active=true;
this.dragon.playAnimation("newAnimation", 1)
this.dragon.on(dragonBones.EventObject.COMPLETE,()=>{
if(cb){
cb();
}
resolve(null)
})
})
}
doHide(cb){
return new Promise((resolve,reject)=>{
this.node.stopAllActions()
cc.tween(this.node)
.to(0.3,{scale:0})
.call(()=>{
if(cb)cb()
resolve(null)
this.node.destroy();
})
.start();
})
}
doFlip(cb=null){ doFlip(cb=null){
this.node.stopAllActions(); this.node.stopAllActions();
if(this.node.scaleX>0){ if(this.node.scaleX>0){
...@@ -70,6 +92,9 @@ export default class card extends cc.Component { ...@@ -70,6 +92,9 @@ export default class card extends cc.Component {
this.backN.active=false this.backN.active=false
}) })
.to(0.25,{scaleX:-1}) .to(0.25,{scaleX:-1})
.call(()=>{
if(cb)cb()
})
.start(); .start();
}else{ }else{
cc.tween(this.node) cc.tween(this.node)
...@@ -80,11 +105,50 @@ export default class card extends cc.Component { ...@@ -80,11 +105,50 @@ export default class card extends cc.Component {
this.backN.active=true this.backN.active=true
}) })
.to(0.25,{scaleX:1}) .to(0.25,{scaleX:1})
.call(()=>{
if(cb)cb()
})
.start(); .start();
} }
} }
asyncDoFlip(cb){
return new Promise((resolve, reject)=>{
//做一些异步操作
this.node.stopAllActions();
if(this.node.scaleX>0){
cc.tween(this.node)
.to(0.25,{scaleX:0})
.call(()=>{
this.iconN.scaleX=-this.iconN.scaleX
this.wordLabel.node.scaleX=-1
this.backN.active=false
})
.to(0.25,{scaleX:-1})
.call(()=>{
if(cb)cb()
resolve(null);
})
.start();
}else{
cc.tween(this.node)
.to(0.25,{scaleX:0})
.call(()=>{
this.iconN.scaleX=-this.iconN.scaleX
this.wordLabel.node.scaleX=1
this.backN.active=true
})
.to(0.25,{scaleX:1})
.call(()=>{
if(cb)cb()
resolve(null);
})
.start();
}
});
}
// update (dt) {} // update (dt) {}
......
This diff is collapsed.
...@@ -23,6 +23,10 @@ export default class SceneComponent extends MyCocosSceneComponent { ...@@ -23,6 +23,10 @@ export default class SceneComponent extends MyCocosSceneComponent {
gameInterval=null; gameInterval=null;
watchTime=null; watchTime=null;
gameTime=null; gameTime=null;
clickNode1:cc.Node=null;
clickNodeData1=null
canTouch=false
completeNum=0;
...@@ -50,7 +54,7 @@ export default class SceneComponent extends MyCocosSceneComponent { ...@@ -50,7 +54,7 @@ export default class SceneComponent extends MyCocosSceneComponent {
super.start(); super.start();
this.initBg(); this.initBg();
this.initData(); this.initData();
this.initTime(); // cc.find("Canvas/uiP/timeN").active=false;
} }
_cantouch = null; _cantouch = null;
...@@ -136,6 +140,7 @@ export default class SceneComponent extends MyCocosSceneComponent { ...@@ -136,6 +140,7 @@ export default class SceneComponent extends MyCocosSceneComponent {
return data return data
} }
initTime(){ initTime(){
// cc.find("Canvas/uiP/timeN").active=true;
let timeN=cc.find("Canvas/uiP/timeN/bg_time"); let timeN=cc.find("Canvas/uiP/timeN/bg_time");
let timeN1=cc.find("Canvas/uiP/timeN/bg_time2"); let timeN1=cc.find("Canvas/uiP/timeN/bg_time2");
this.watchTime=this.data.questions[0].watchTime; this.watchTime=this.data.questions[0].watchTime;
...@@ -158,16 +163,29 @@ export default class SceneComponent extends MyCocosSceneComponent { ...@@ -158,16 +163,29 @@ export default class SceneComponent extends MyCocosSceneComponent {
if(numTime<=5){ if(numTime<=5){
timeN.active=false; timeN.active=false;
timeN1.active=true; timeN1.active=true;
if(numTime<=1){ // if(this.gameState=="game"){
if(numTime==1)this.playLocalAudio("time1") if(numTime<=1){
}else{ if(numTime==1)this.playLocalAudio("time1")
this.playLocalAudio("time2") }else{
} this.playLocalAudio("time2")
if(this.gameState=="watching"){
if(numTime==1||numTime==2||numTime==3){
} }
} // }else{
if(this.gameState=="watching"){
if(numTime==1||numTime==2||numTime==3){
this.countDown.active=true;
this.countDown.stopAllActions();
this.countDown.scale=1;
this.getSprforNode(numTime, this.countDown);
cc.tween( this.countDown)
.to(0.8,{scale:0.7})
.call(()=>{
this.countDown.active=false;
})
.start()
}
}
// }
} }
...@@ -177,27 +195,92 @@ export default class SceneComponent extends MyCocosSceneComponent { ...@@ -177,27 +195,92 @@ export default class SceneComponent extends MyCocosSceneComponent {
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").doFlip(()=>{ children[i].getComponent("card").asyncDoFlip(()=>{
if(i==children.length-1)this.startWatch();
}) })
} }
} }
startWatch(){ startWatch(){
this.canTouch=false
this.gameState=="watching" this.gameState=="watching"
this.initTime();
this.clearntervals(); this.clearntervals();
this.initTime();
this.watchInterval=setInterval(()=>{ this.watchInterval=setInterval(()=>{
this.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;
for(let i=0;i<children.length;i++){
children[i].getComponent("card").asyncDoFlip(()=>{
if(i==children.length-1)this.startGame();
})
}
} }
this.updateTime(); this.updateTime();
},1000) },1000)
}; };
startGame(){
this.canTouch=true;
this.gameState="game"
this.clearntervals();
this.initTime();
this.gameInterval=setInterval(()=>{
this.gameTime--;
console.log("watchtime=====",this.gameTime)
if( this.gameTime<=0){
this.clearntervals();
}
this.updateTime();
},1000)
}
clickCard(node,data){
if(this.canTouch){
if(!this.clickNode1){
this.clickNode1=node;
this.clickNodeData1=data;
this.clickNode1.getComponent("card").asyncDoFlip()
this.playAudioByUrl( this.clickNodeData1.audio);
}else{
if(this.clickNode1==node){
return;
// this.playAudioByUrl( this.clickNodeData1.audio);
}else{
this.canTouch=false
Promise
.all([node.getComponent("card").asyncDoFlip(), this.playAudioByUrl( data.audio)])
.then(()=>{
Promise.all([node.getComponent("card").playDragon(), this.clickNode1.getComponent("card").playDragon(),this.playLocalAudio("true")])
.then(()=>{
Promise.all([node.getComponent("card").doHide(), this.clickNode1.getComponent("card").doHide()])
.then(()=>{
this.canTouch=true;
this.clickNode1=null
this.clickNodeData1=null;
this.completeNum++
if(this.completeNum== this.data.questions[this.questionIndex].options.length/2){
console.log("allTrue===")
this.clearntervals();
}
console.log("allActionFish=====")
})
})
}
)
}
}
}
}
clearntervals(){ clearntervals(){
// cc.find("Canvas/uiP/timeN").active=false;
if(this.watchInterval){ if(this.watchInterval){
clearInterval(this.watchInterval); clearInterval(this.watchInterval);
} }
...@@ -206,7 +289,6 @@ export default class SceneComponent extends MyCocosSceneComponent { ...@@ -206,7 +289,6 @@ export default class SceneComponent extends MyCocosSceneComponent {
} }
} }
initView() { initView() {
this.initBg(); this.initBg();
this.initBtn(); this.initBtn();
......
...@@ -105,17 +105,17 @@ export class MyCocosSceneComponent extends cc.Component { ...@@ -105,17 +105,17 @@ export class MyCocosSceneComponent extends cc.Component {
}); });
} }
log (str) { log(str) {
const node = cc.find('middleLayer'); const node = cc.find('middleLayer');
if(node){ if (node) {
node.getComponent('middleLayer').log(str); node.getComponent('middleLayer').log(str);
}else{ } else {
cc.log(str); cc.log(str);
} }
} }
onLoadEnd() { onLoadEnd() {
} }
...@@ -132,7 +132,7 @@ export class MyCocosSceneComponent extends cc.Component { ...@@ -132,7 +132,7 @@ export class MyCocosSceneComponent extends cc.Component {
// ------------------------------------------------ // ------------------------------------------------
getSprNode(resName) { getSprNode(resName) {
const sf = cc.find('Canvas/res/img/' + resName).getComponent(cc.Sprite).spriteFrame; const sf = cc.find('Canvas/res/img/' + resName).getComponent(cc.Sprite).spriteFrame;
...@@ -140,6 +140,10 @@ export class MyCocosSceneComponent extends cc.Component { ...@@ -140,6 +140,10 @@ export class MyCocosSceneComponent extends cc.Component {
node.addComponent(cc.Sprite).spriteFrame = sf; node.addComponent(cc.Sprite).spriteFrame = sf;
return node; return node;
} }
getSprforNode(resName, node) {
const sf = cc.find('Canvas/res/img/' + resName).getComponent(cc.Sprite).spriteFrame;
node.getComponent(cc.Sprite).spriteFrame = sf;
}
getSpriteFrimeByUrl(url, cb) { getSpriteFrimeByUrl(url, cb) {
...@@ -161,7 +165,7 @@ export class MyCocosSceneComponent extends cc.Component { ...@@ -161,7 +165,7 @@ export class MyCocosSceneComponent extends cc.Component {
} }
}) })
} }
getSprForNodeByUrl(url,node,cb=null) { getSprForNodeByUrl(url, node, cb = null) {
const spr = node.getComponent(cc.Sprite); const spr = node.getComponent(cc.Sprite);
this.getSpriteFrimeByUrl(url, (sf) => { this.getSpriteFrimeByUrl(url, (sf) => {
spr.spriteFrame = sf; spr.spriteFrame = sf;
...@@ -173,15 +177,19 @@ export class MyCocosSceneComponent extends cc.Component { ...@@ -173,15 +177,19 @@ export class MyCocosSceneComponent extends cc.Component {
playAudioByUrl(audio_url, cb = null) { playAudioByUrl(audio_url, cb = null) {
if (audio_url) { if (audio_url) {
cc.assetManager.loadRemote(audio_url, (err, audioClip) => { return new Promise((resole, reject) => {
const audioId = cc.audioEngine.play(audioClip, false, 0.8); cc.assetManager.loadRemote(audio_url, (err, audioClip) => {
if (cb) { cc.audioEngine.stopAll();
const audioId = cc.audioEngine.play(audioClip, false, 0.8);
cc.audioEngine.setFinishCallback(audioId, () => { cc.audioEngine.setFinishCallback(audioId, () => {
cb(); if(cb)cb();
}); resole(null);
} })
}); })
}else{ })
} else {
cb && cb(); cb && cb();
} }
} }
......
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