Commit 7c2d2857 authored by Tt's avatar Tt

基础玩法完成,再核对一次需求,然后开始调整动画

parent 6945f6fb
This diff is collapsed.
......@@ -137,55 +137,7 @@ cc.Class({
this.initSingleData();
this.initAudio();
this.initView();
// this.initButton();
},
initButton() {
//触碰判断
let item = pg.view.find(this, "items/item");
item.on(cc.Node.EventType.TOUCH_START, this.onStartItem, this);
item.on(cc.Node.EventType.TOUCH_END, this.onEndItem, this);
item.on(cc.Node.EventType.TOUCH_MOVE, this.onMoveItem, this);
item.on(cc.Node.EventType.TOUCH_CANCEL, this.onCancelItem, this);
},
onStartItem(touch) {
this._startPos = cc.v2(touch.target.x, touch.target.y);
let touchPos = touch.getLocation();
touch.target.x = touchPos.x - 1280 / 2;
touch.target.y = touchPos.y - 720 / 2;
},
onEndItem(touch) {
let box_0 = pg.view.find(this, "box/box_0");
//检测碰撞
if (this.checkCollider(touch.target, box_0)) {
} else {
//碰撞失败退回原位置
touch.target.x = this._startPos.x;
touch.target.y = this._startPos.y;
}
},
onMoveItem(touch) {
//获取到的location是 当前点击的位置 而不是按钮原本应该所在的位置。
let touchPos = touch.getLocation();
touch.target.x = touchPos.x - 1280 / 2;
touch.target.y = touchPos.y - 720 / 2;
},
onCancelItem(touch) {
console.log(touch);
},
checkCollider(item, box) {
return item.x > box.x - box.width / 2
&& item.x < box.x + box.width / 2
&& item.y > box.y - box.height / 2
&& item.y < box.y + box.height / 2;
},
......@@ -268,16 +220,20 @@ cc.Class({
let addX = 190;
let y = 75;
for (let i = 0; i < sonleis.length; i++) {
let data = sonleis[i];
let sonClone = cc.instantiate(son);
sonClone.active = true;
let posX = x + addX * i;
let posY = y;
sonClone.x = posX;
sonClone.y = posY;
sonClone.data = data;
pg.view.setString(pg.view.find(sonClone, "txt"), data.title);
box.addChild(sonClone);
}
},
initBox() {
this._boxItems = [];
//刷新子类
let son = pg.view.find(this, "box/box_0");
let box = pg.view.find(this, "box");
......@@ -289,12 +245,15 @@ cc.Class({
let y = -62;
for (let i = 0; i < sonleis.length; i++) {
let sonClone = cc.instantiate(son);
let data = sonleis[i];
sonClone.data = data;
sonClone.active = true;
let posX = x + addX * i;
let posY = y;
sonClone.x = posX;
sonClone.y = posY;
box.addChild(sonClone);
this._boxItems.push(sonClone);
}
},
initItems() {
......@@ -309,11 +268,14 @@ cc.Class({
let addY = -90;
for (let i = 0; i < sonleis.length; i++) {
let sonClone = cc.instantiate(son);
let data = sonleis[i];
sonClone.data = data;
sonClone.active = true;
let posX = x + addX * (i % 7);
let posY = y + addY * Math.floor(i / 7);
sonClone.x = posX;
sonClone.y = posY;
this.initButton(sonClone);
box.addChild(sonClone);
}
} else {
......@@ -325,6 +287,8 @@ cc.Class({
let arr = [3, 4, 5, 6, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30];
for (let i = 0; i < sonleis.length; i++) {
let sonClone = cc.instantiate(son);
let data = sonleis[i];
sonClone.data = data;
sonClone.active = true;
let posX = x + addX * (arr[i] % 10);
let posY = y + addY * Math.floor(arr[i] / 10);
......@@ -332,11 +296,72 @@ cc.Class({
sonClone.y = posY;
sonClone.scaleX = scale;
sonClone.scaleY = scale;
this.initButton(sonClone);
box.addChild(sonClone);
}
}
},
initButton(item) {
item.on(cc.Node.EventType.TOUCH_START, this.onStartItem, this);
item.on(cc.Node.EventType.TOUCH_END, this.onEndItem, this);
item.on(cc.Node.EventType.TOUCH_MOVE, this.onMoveItem, this);
item.on(cc.Node.EventType.TOUCH_CANCEL, this.onCancelItem, this);
},
onStartItem(touch) {
this._startPos = cc.v2(touch.target.x, touch.target.y);
let touchPos = touch.getLocation();
touch.target.x = touchPos.x - 1280 / 2;
touch.target.y = touchPos.y - 720 / 2;
},
onEndItem(touch) {
//检测碰撞
let box = this.getCollider(touch.target);
if (box) {
//成功 失败的判断 根据id
let successed = box.data.child.some(dt => dt.cardId == touch.target.data.cardId);
if (successed) {
alert("成功")
} else {
alert("失败")
//碰撞失败退回原位置
touch.target.x = this._startPos.x;
touch.target.y = this._startPos.y;
}
} else {
//碰撞失败退回原位置
touch.target.x = this._startPos.x;
touch.target.y = this._startPos.y;
}
},
onMoveItem(touch) {
//获取到的location是 当前点击的位置 而不是按钮原本应该所在的位置。
let touchPos = touch.getLocation();
touch.target.x = touchPos.x - 1280 / 2;
touch.target.y = touchPos.y - 720 / 2;
},
onCancelItem(touch) {
console.log(touch);
},
getCollider(item) {
for (let i = 0; i < this._boxItems.length; i++) {
if (this.checkCollider(item, this._boxItems[i])) return this._boxItems[i];
}
return null;
},
checkCollider(item, box) {
return item.x > box.x - box.width / 2
&& item.x < box.x + box.width / 2
&& item.y > box.y - box.height / 2
&& item.y < box.y + box.height / 2;
},
// updateItem(item, data) {
// let img = pg.view.find(item, `img`);
......
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