在game_layer.js 新建方法 scortZoder(target) 修改层级的zindex让 拖动的拼图 永远在上面
puzzleCellTouchStart(target){ //开启触摸 target.setOnDragging(); this.scortZoder(target); this.refreshPuzzleCellPos(); }, puzzleCellTouchEnd(target){ }, scortZoder(target){ for (let index = 0; index < this.puzzleCellList.length; index++) { this.puzzleCellList[index].zIndex=10; } target.node.zIndex=100; },
能puzzle_cell添加一个label
puzzleCellTouchEnd(target){ //触摸结束 找到离我最近的点 let minMapDis = 1000; let purMapPos = undefined; 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; } } if(minMapDis<140){ target.node.position = purMapPos; } },
在load代码中添加tomMapCellList 全局变量
吸附功能效果如下。
站长微信:xiaomao0055
站长QQ:14496453