在Monster.ts中写一个接口,拿到怪物的当前坐标和下一个拐点坐标,通过动作tween让怪物移动。
通过递归调用自己来实现不断地向下一个拐点移动。
//怪物自己移动到最后。
runWithPath(){
//获取怪物当前坐标
let curPos =cc.v2(this.node.x,this.node.y);
//索引加1
this.index++;
//获取下一个拐点坐标
let endPos = this.arrPos[this.index];
//以动作让怪物移动
cc.tween(this.node)
.to(1.0,{
position:cc.v3(endPos.x,endPos.y,0)})
.call(this.runWithPath.bind(this))