本节讲 可以将下面的拼图 拉到上面

在puzzle_cell.js 中添加代码
//状态机
const PUZZLESTATE = {
OnTouchMap:1,
OnDragging:2,
OnMap:3
}
//状态机
const PUZZLESTATE = {
OnTouchMap:1,
OnDragging:2,
OnMap:3
}
this.state = PUZZLESTATE.OnTouchMap;
getIsOnTouchMap(){
if(this.state==PUZZLESTATE.OnTouchMap){
return true;
}else{
return false;
}
},
refreshPuzzleCellPos(){
//刷新下部显示UI
let index = 0 ;
for(let i in this.puzzleCellList){
let puzzleCell = this.puzzleCellList[i];
if(puzzleCell.getComponent('puzzle_cell').getIsOnTouchMap()){
if(index<3){
puzzleCell.position= this.touchCellList[i].position;
}else {
puzzleCell.active= false;
}
index++;
}
}
}, this.node.parent.getComponent('game_layer').puzzleCellTouchStart(self);
this.node.parent.getComponent('game_layer').puzzleCellTouchEnd(self);
refreshPuzzleCellPos(){
//刷新下部显示UI
let index = 0 ;
for(let i in this.puzzleCellList){
let puzzleCell = this.puzzleCellList[i];
puzzleCell.active = true;
if(puzzleCell.getComponent('puzzle_cell').getIsOnTouchMap()){// state==PUZZLESTATE.OnTouchMap 返回 true this.state = PUZZLESTATE.OnTouchMap;
if(index<3){
puzzleCell.position= this.touchCellList[index].position;
}else {
puzzleCell.active= false;
}
index++;
}
}
},
puzzleCellTouchStart(target){
//开启触摸
target.setOnDragging();
this.refreshPuzzleCellPos();
},
puzzleCellTouchEnd(target){
} setOnDragging(){
this.state = PUZZLESTATE.OnDragging;
}let currentPos = self.node.parent.convertToNodeSpaceAR(event.getLocation());

站长微信:xiaomao0055
站长QQ:14496453