setOnMap(){
this.state = PUZZLESTATE.OnMap;
}

setOnTouch(){
this.state = PUZZLESTATE.OnTouchMap;
}

puzzleCellTouchEnd(target){
//触摸结束 找到离我最近的点
let minMapDis = 1000;
let purMapPos = undefined;
//遍历 顶部的6个位置, 判断谁近我近,我就吸附到谁身上。
for (let index = 0; index < this.topMapCellList.length; index++) {
let topMapCell = this.topMapCellList[index];
//let dis = cc.pDistance(topMapCell.position,target.position);//取得 2点之间的距离 这个方法 过时了
// Sorry, cc.pDistance is removed, please use p1.sub(p2).mag() instead.
let dis = topMapCell.position.sub(target.node.position).mag();//取得 2点之间的距离 这个方法 过时了
if(dis<minMapDis){
minMapDis = dis;
purMapPos = topMapCell.position;
}
}
//当前拿的碎片 和 已经放到顶部的碎片 比较,离我最近的是谁。
//结束 触摸后,如果离我太近 你回归底部
let minPuzzleDis = 10000;
//遍历拼图碎片 puzzleCellList
for(let i in this.puzzleCellList){
let puzzle = this.puzzleCellList[i];
//判断 状态onmap 已经放到了上面6个格格当中了
if(puzzle.getComponent('puzzle_cell').getIsOnMap()){
let dis = puzzle.position.sub(target.node.position).mag();
if(dis<minPuzzleDis){
minPuzzleDis = dis;
}
}
}
console.log("离我最近的距离是:"+minPuzzleDis);
// 离我的距离要大于160 不然你回归底部。
if(minMapDis<140&&minPuzzleDis>160){
//吸附到顶部离我最近的点
target.node.position = purMapPos;
target.setOnMap();
}else{
//放的位置不对,自动回归原点
target.setOnTouch();
}
this.refreshPuzzleCellPos();
},站长微信:xiaomao0055
站长QQ:14496453