Commit 04f41b74 authored by Tt's avatar Tt

1

parent 4d9f0709
......@@ -4579,7 +4579,7 @@
"__id__": 91
},
"_children": [],
"_active": false,
"_active": true,
"_components": [
{
"__id__": 93
......@@ -4676,7 +4676,7 @@
"__id__": 91
},
"_children": [],
"_active": false,
"_active": true,
"_components": [
{
"__id__": 95
......
......@@ -278,12 +278,9 @@ cc.Class({
let posY = y + addY * Math.floor(i / 7);
sonClone.x = posX;
sonClone.y = posY;
sonClone.cardState = 0;
this.initButton(sonClone);
let icon = sonClone.getChildByName("icon");
let txt = sonClone.getChildByName("txt");
icon.active = false;
txt.active = true;
pg.view.setString(txt, data.txt);
this.updateItem(sonClone);
box.addChild(sonClone);
}
} else {
......@@ -304,17 +301,71 @@ cc.Class({
sonClone.y = posY;
sonClone.scaleX = scale;
sonClone.scaleY = scale;
sonClone.cardState = 0;
this.initButton(sonClone);
let icon = sonClone.getChildByName("icon");
let txt = sonClone.getChildByName("txt");
icon.active = false;
txt.active = true;
pg.view.setString(txt, data.txt);
this.updateItem(sonClone);
box.addChild(sonClone);
}
}
},
updateItem(item) {
let data = item.data;
let bg = item.getChildByName("bg");
let icon = item.getChildByName("icon");
let txt = item.getChildByName("txt");
let chose = item.getChildByName("chose");
let fail = item.getChildByName("fail");
let success = item.getChildByName("success");
if (item.cardState == 0) {
//文字
icon.active = false;
txt.active = true;
pg.view.visible(pg.view.find(success, "icon"), false);
pg.view.visible(pg.view.find(success, "txt"), true);
} else if (item.cardState == 1) {
//图片
icon.active = true;
txt.active = false;
pg.view.visible(pg.view.find(success, "icon"), true);
pg.view.visible(pg.view.find(success, "txt"), false);
}
pg.view.setString(txt, data.txt);
pg.view.setString(pg.view.find(success, "txt"), data.txt);
switch (item.moveState) {
case 1:
bg.active = true;
chose.active = true;
fail.active = false;
success.active = false;
break;
case 2:
bg.active = false;
chose.active = false;
fail.active = false;
success.active = true;
icon.active = false;
txt.active = false;
break;
case 3:
bg.active = false;
chose.active = false;
fail.active = true;
success.active = false;
break;
default:
bg.active = true;
chose.active = false;
fail.active = false;
success.active = false;
break;
}
},
moveItem(item, pos) {
item.x = pos.x;
item.y = pos.y;
},
initButton(item) {
item.on(cc.Node.EventType.TOUCH_START, this.onStartItem, this);
item.on(cc.Node.EventType.TOUCH_END, this.onEndItem, this);
......@@ -330,6 +381,9 @@ cc.Class({
// touch.target.x = touchPos.x - 1280 / 2;
// touch.target.y = touchPos.y - 720 / 2;
},
//1.移动效果--在节点上绑定一个运动的type 根据type来刷新按钮效果 刷新type的方法,和具体的执行的时候刷新type
//2.成功效果--
//3.失败效果--
onEndItem(touch) {
let item = touch.target;
let touchPos = touch.getLocation();
......@@ -344,19 +398,11 @@ cc.Class({
height: 50,//item.height
})) {
//回归原位
item.x = this._startPos.x;
item.y = this._startPos.y;
this.moveItem(item, this._startPos);
//变换动画
ani.flipX0(item).then(() => {
let icon = item.getChildByName("icon");
let txt = item.getChildByName("txt");
if (txt.active) {
icon.active = true;
txt.active = false;
} else {
icon.active = false;
txt.active = true;
}
item.cardState = item.cardState == 0 ? 1 : 0;
this.updateItem(item);
ani.flipX1(item);
})
return;
......@@ -367,18 +413,19 @@ cc.Class({
//成功 失败的判断 根据id
let successed = box.data.child.some(dt => dt.cardId == item.data.cardId);
if (successed) {
alert("成功")
item.moveState = 2;
this.updateItem(item);
} else {
alert("失败")
//碰撞失败退回原位置
item.x = this._startPos.x;
item.y = this._startPos.y;
item.moveState = 3;
this.updateItem(item);
// //碰撞失败退回原位置
setTimeout(() => {
this.moveItem(item, this._startPos);
}, 100);
}
} else {
//碰撞失败退回原位置
item.x = this._startPos.x;
item.y = this._startPos.y;
this.moveItem(item, this._startPos);
}
},
onMoveItem(touch) {
......@@ -397,6 +444,8 @@ cc.Class({
})) {
return;
}
item.moveState = 1;
this.updateItem(item);
touch.target.x = touchPos.x - 1280 / 2;
touch.target.y = touchPos.y - 720 / 2;
},
......@@ -474,8 +523,6 @@ cc.Class({
......
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